#Arin Modi

1 messages · Page 1 of 1 (latest)

hidden quarryBOT
keen wren
#

Can you she a snippet of code that runs leading to this error?

#

Are you making some manual calls to the payment intent using a publishable key and client secret combination?

trail timber
#

Method named presentPaymentSheet causing this problem after standalone build

keen wren
#

What does your call for that look like?

trail timber
#

Let me share the snippet

trail timber
#

const userData = props.route.params.Data;

const apiUrl = ""

const [apiLoader, setApiLoader]=useState(true);

const fetchPaymentSheetParams = async () => {
  const response = await fetch(apiUrl + `/create-subscription`, {
    method: 'POST',
    headers : {
      'Content-Type': 'application/json'
    },
    body : JSON.stringify({
      email: userData.email,
      name: userData.name
    })
  });

  const { subscriptionId, clientSecret, customerId, key } = await response.json();

  return {
    subscriptionId,
    clientSecret,
    customerId,
    key
  }
}

const initializePaymentSheet = async () => {
  const {
    subscriptionId,
    clientSecret,
    customerId,
    key
  } = await fetchPaymentSheetParams();

  const { error } = await initPaymentSheet({
    merchantDisplayName: "Hide Trade",
    customerId: customerId,
    paymentIntentClientSecret: clientSecret,
    customerEphemeralKeySecret : key
  });

  console.log(error)

  setApiLoader(false);
};

const openPaymentSheet = async () => {
  const { error } = await presentPaymentSheet();

  if (error) {
    Alert.alert(`Error code: ${error.code}`, error.message);
  } else {
    Alert.alert('Success', 'Your Subscription is Active Now', [{ 
      text : "OK", onPress : () => {
        props.navigation.dispatch(StackActions.replace('Tabs'));
      }
    }], {
      cancelable : false
    });
  }
}

useEffect(() => {
  initializePaymentSheet();
}, []);
keen wren
#

So here you're trying to confirm payment on the first invoice of a new subscription, using default_incomplete?

trail timber
#

Yes, Exactly

#

That code is on server side when creating subscription

#

app.post("/create-subscription", async (req, res) => {
console.log(req.body);

const customers = await stripe.customers.list({
    email : req.body.email
});

let cid = "";

if (customers.data.length == 0) {
    const customer = await stripe.customers.create({
        email: req.body.email,
        name: req.body.name
    });
    cid = customer.id;
} else {
    console.log("Exists...");
    cid = customers.data[0].id;
}

const ephemeralKey = await stripe.ephemeralKeys.create(
    {customer: cid},
    {apiVersion: '2022-11-15'}
);

console.log(ephemeralKey);

const priceId = "";

try {
    const subscription = await stripe.subscriptions.create({
      customer: cid,
      items: [{
        price: priceId,
      }],
      payment_behavior: 'default_incomplete',
      payment_settings: { save_default_payment_method: 'on_subscription' },
      expand: ['latest_invoice.payment_intent'],
    });

    console.log(subscription.latest_invoice.payment_intent.client_secret);

    res.send({
      subscriptionId: subscription.id,
      clientSecret: subscription.latest_invoice.payment_intent.client_secret,
      customerId : cid,
      key : ephemeralKey.secret
    });
} catch (error) {
    return res.status(400).send({ error: { message: error.message } });
}

});

keen wren
#

Can you share an example Payment Intent id, or your account ID?

trail timber
#

While testing using expo go works perfectly, but after standalone build not working

keen wren
#

Can you explain more about that, what do you mean?

#

And do you have an example PI I can look at?

trail timber
#

here,

keen wren
#

Thanks -- i'm removing the object and just saving this id here for reference: pi_3MWRTqLt3bt57eoN0s8AZqEY

trail timber
#

I want to say that, when I am running app by expo start it is working as expected,

But after eas build it is giving me this error

keen wren
#

Can you try adding some logging of the client secret you pass?

#

That specific error suggests that the client secret value might be wrong in some way

pastel yarrow
#

@trail timber 👋

trail timber
#

Hey

#

It's really weird that only after build apk it is giving this error

#

Do you have any idea about that?

pastel yarrow
#

Do you have a bit more detailed stacktrace or screenshot?

#

It sounds weird since the error looks like only a missmatch

trail timber
#

But when running in the expo go, it is working

trail timber
pastel yarrow
#

Ah that means you have been using a PaymentIntent secret from different account than the PublishableKey

trail timber
#

So why it is working inside expo go

pastel yarrow
#

It may depends on the Publishable Key you configured between 2 builds

#

You can log the payment intent id and the publishable key to compare

#

For example, what are the Payment Intent Id pi_xxx when it didn't work and when it was working? What are the Publishable Key for each builds?

trail timber
#

But i have only one publishable key which I configured directly inside StripePrpvider parameter.

#

Does it effect defining Live Publishable Key Directly in stripe provider?

pastel yarrow
#

You probably defined it somewhere

#

First let's log the PaymentIntent IDs in both cases (working vs non-working)

trail timber
#

Also, do we need set anything inside app.json ?

Or do we need to perform any step when moving from test to live, other than changing the keys?

pastel yarrow
#

You should set Live Publishable key for production build and Test Publishable Key for test build, that's correct, but you also need to use a different endpoint, each use Live Secret Key and Test Secret Key for your build

#

Live Publishable Key build ---request---> a Live endpoint which uses Live Secret Key
Test Publishable Key build ---request---> a Test endpoint which uses Test Secret Key

trail timber
#

Yes, I am doing that

#

Can we see publishable key of payment intent in the stripe dashboard?

pastel yarrow
#

There is no Publishable Key "of" PaymentIntent. You can only see the PaymentIntent in dashboard by putting its id into the search box, and see if that's Test mode of Live mode

trail timber
#

I checked at the stripe dashboard and it is showing LiveMode true for both the builds

pastel yarrow
#

So both the PI was in Live mode?

#

To double check can you provide 2 PI Ids here?

trail timber
#

Yes, both are in Live Mode

#

Give me some time, I will give you both PI ids

trail timber
#

Not Working PI : pi_3MWaRJLt3bt57eoN1zaMcGPv

#

Working PI : pi_3MWc1xLt3bt57eoN0gheudEk

#

please guide me how to solve this ?

pastel yarrow
#

Okie they are both Live mode PIs comes from a same Stripe Account

#

Now it comes to which Publishable Key you use in each cases

#

Can you also log the Not Working and the Working Publishable Key?

trail timber
#

okay, but how can I log that ?

#

means where can i get the publishable key ?

pastel yarrow
trail timber
#

By Following Above Documents, I have given the publishablekey in StripeProvider element, generated both builds

#

So there is no way those two can be different

verbal nebula
#

Taking over here, can you summarise the issue?

trail timber
# trail timber

Sure, when I run the app using expo go, payment sheet is created as expected but after generating eas build for android it is giving above error

verbal nebula
#

Ok, can you share the pi_xx ID

trail timber
#

Not Working PI : pi_3MWaRJLt3bt57eoN1zaMcGPv
Working PI : pi_3MWc1xLt3bt57eoN0gheudEk

verbal nebula
#

Can you also share the pk_xxx you're using?

#

The error indicates you're using the wrong API key (i.e. from a different account, not acct_1MMu5kLt3bt57eoN which created those payments)

trail timber
#

for which PI not working or working ?

verbal nebula
#

Well you should be using the same pk_xxx for both

#

I'm not sure why you'd change that

trail timber
#

I have only one pk which I have configured inside StripeProvider

#

There is no other pk

verbal nebula
#

Can you share that please

trail timber
#

my live publishablekey ?

verbal nebula
#

But I suspect that's not the case, as the error implies

verbal nebula
#

Not sure why you're using live keys if you're testing anyway

trail timber
#

I have tested using test keys, it is perfectly working, than I changed my test keys to live keys and generate the build but it gave me error as I shared,

verbal nebula
#

You can redact that now if you wish

#

But yes, that belongs to the same account: acct_1MMu5kLt3bt57eoN

#

I suspect there's an errant pk_xxx key somewhere in your build still. I recommend logging it out in your application in the flow just before the error throws (i.e. when initialising the Payment Sheet)

trail timber
#

Ok, can tell me the way to clear the cache of expo eas build

verbal nebula
#

I'm not sure I'm afraid

trail timber
#

I think creating toast for the publishable key will much better, what do you think ?

verbal nebula
#

I don't know what that means?

trail timber
#

oh, don't worry

trail timber
#

Hey Thanks, I got the error, error is not with stripe.
Actually The Code I am Changing isn't reflecting in the build that's why My Key Updation from test to live also isn't reflected, and that's causing the issue

verbal nebula
#

Figured as much! Glad you sorted it out

trail timber
#

Thanks For Your Help

verbal nebula
#

np