#Arin Modi
1 messages · Page 1 of 1 (latest)
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?
Method named presentPaymentSheet causing this problem after standalone build
What does your call for that look like?
Let me share the snippet
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();
}, []);
So here you're trying to confirm payment on the first invoice of a new subscription, using default_incomplete?
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 } });
}
});
Can you share an example Payment Intent id, or your account ID?
While testing using expo go works perfectly, but after standalone build not working
Can you explain more about that, what do you mean?
And do you have an example PI I can look at?
here,
Thanks -- i'm removing the object and just saving this id here for reference: pi_3MWRTqLt3bt57eoN0s8AZqEY
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
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
You should confirm what you log matches the client_secret you can see in your request logs for the Sub (and PI) creation:
https://dashboard.stripe.com/logs/req_3SGmygJLxeDGEw
@trail timber 👋
Hey
It's really weird that only after build apk it is giving this error
Do you have any idea about that?
Do you have a bit more detailed stacktrace or screenshot?
It sounds weird since the error looks like only a missmatch
This is the error, after build
Ah that means you have been using a PaymentIntent secret from different account than the PublishableKey
So why it is working inside expo go
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?
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?
You probably defined it somewhere
First let's log the PaymentIntent IDs in both cases (working vs non-working)
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?
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
Yes, I am doing that
Can we see publishable key of payment intent in the stripe dashboard?
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
I checked at the stripe dashboard and it is showing LiveMode true for both the builds
Not Working PI : pi_3MWaRJLt3bt57eoN1zaMcGPv
Working PI : pi_3MWc1xLt3bt57eoN0gheudEk
please guide me how to solve this ?
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?
It depends on how do you build your app. You use React Native so it should be this step: https://stripe.com/docs/payments/accept-a-payment?platform=react-native&ui=payment-sheet#stripe-initialization
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
Taking over here, can you summarise the issue?
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
Ok, can you share the pi_xx ID
Not Working PI : pi_3MWaRJLt3bt57eoN1zaMcGPv
Working PI : pi_3MWc1xLt3bt57eoN0gheudEk
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)
for which PI not working or working ?
Well you should be using the same pk_xxx for both
I'm not sure why you'd change that
I have only one pk which I have configured inside StripeProvider
There is no other pk
Can you share that please
my live publishablekey ?
But I suspect that's not the case, as the error implies
Yes, they're fine to share publicly (hence the name): https://stripe.com/docs/keys
Not sure why you're using live keys if you're testing anyway
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,
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)
Ok, can tell me the way to clear the cache of expo eas build
I'm not sure I'm afraid
I think creating toast for the publishable key will much better, what do you think ?
I don't know what that means?
oh, don't worry
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
Figured as much! Glad you sorted it out
Thanks For Your Help
np