expo: Stripe paymentRequestWithApplePayAsync doesn't create an actual payment in Stripe
đ Bug Report
Summary of Issue
When I follow the docs by expo and stripe and attempt to call paymentRequestWithApplePayAsync I get a successful response token back and no errors but a payment is never actually created in the stripe dashboard.
Environment - output of expo diagnostics & the platform(s) youâre targeting
Expo SDK 37 âexpo-payments-stripeâ: â~8.1.0â
Expo CLI 3.28.2 environment info: System: OS: macOS 11.0.1 Shell: 3.2.57 - /bin/bash Binaries: Node: 12.16.2 - /usr/local/bin/node npm: 6.14.4 - /usr/local/bin/npm Watchman: 4.7.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.8.4 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.3, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 Android SDK: API Levels: 23, 27, 28, 29 Build Tools: 26.0.3, 27.0.3, 28.0.0, 28.0.3 Android NDK: 20.0.5594570 IDEs: Android Studio: 3.4 AI-183.5429.30.34.5452501 Xcode: 12.3/12C33 - /usr/bin/xcodebuild npmPackages: expo: ^37.0.0 => 37.0.12 react: 16.9.0 => 16.9.0 react-native: https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz => 0.61.4 react-navigation: ^4.1.1 => 4.3.9 npmGlobalPackages: expo-cli: 3.28.2 Expo Workflow: managed
Reproducible Demo
` payPressed = async () => { console.log(âpay pressedâ);
const amount = '10.00';
const label = 'some label';
try {
const deviceSupportsAndUserHasExisting =
Platform.OS === 'ios' ? await Stripe.canMakeApplePayPaymentsAsync() : await Stripe.canMakeAndroidPayPaymentsAsync();
const deviceSupportsPayment = Platform.OS === 'ios' ? await Stripe.deviceSupportsApplePayAsync() : await Stripe.deviceSupportsAndroidPayAsync();
console.log('canMake, deviceSupports: ', deviceSupportsAndUserHasExisting, deviceSupportsPayment);
if (deviceSupportsAndUserHasExisting && deviceSupportsPayment) {
const items = [
{
label,
amount,
},
{
label: 'Example, Inc',
amount,
},
];
const options = {
total_price: amount,
currency_code: 'USD',
line_items: [
{
currency_code: 'USD',
description: label,
total_price: amount,
unit_price: amount,
quantity: '1',
},
],
};
console.log('trying things with items: ', items);
const token =
Platform.OS === 'ios' ? await Stripe.paymentRequestWithApplePayAsync(items, {}) : await Stripe.paymentRequestWithAndroidPayAsync(options);
console.log('token: ', token);
if (token) {
console.log('paymentResp token: ', token);
if (Platform.OS === 'ios') {
console.log('complete the apple pay');
const completeResp = await Stripe.completeApplePayRequestAsync();
console.log('complete the apple pay resp: ', completeResp);
}
} else {
console.log('no paymentReq token :(');
if (Platform.OS === 'ios') {
Stripe.cancelApplePayRequestAsync();
}
this.setState({ paymentNotSupportedMsg: 'Somehting went wrong with your payment.', showCustySupport: true });
}
} else {
// tell them if it's there device or if the devices has no existing payment method
let paymentNotSupportedMsg = '';
const payProvider = Platform.OS === 'ios' ? 'Apple' : 'Google';
if (!deviceSupportsPayment) {
paymentNotSupportedMsg = `Example app uses ${payProvider} Pay for this piece. Your device does not support ${payProvider} Pay.`;
} else if (!deviceSupportsAndUserHasExisting) {
paymentNotSupportedMsg = `Example app uses ${payProvider} Pay for this piece. You need to setup a payment method in ${payProvider} Pay.`;
}
this.setState({ paymentNotSupportedMsg, showCustySupport: true });
}
} catch (err) {
console.log('payPressed err: ', err);
if (Platform.OS === 'ios') {
Stripe.cancelApplePayRequestAsync();
}
}
};
`
Steps to Reproduce
Expected Behavior vs Actual Behavior
If something is failing with the call to paymentRequestWithApplePayAsync I would expect to see an error message so I can correct something. The actual behavior is that something isnât actually creating a payment in the stripe dashboard and I have no visibility into why.
Relevant Information
I am doing all this in âtest modeâ of stripe with my test api keys. I can see âsuccessfulâ api token responses in the stripe developers/logs section just nothing ever shows up in the payments section of the dashboard.
Also of note, I started this process of troubleshooting by going through 3 levels of Stripe support thinking that I had something mis-configured on that end. They insisted that I try and get to the bottom of it with someone from expo that I had things configured ok on the stripe end. Their exact words were: âAs long as youâre not seeing the successful payment under Payment page it means the checkout is not working.â
Thank you in advance for any help or guidance that you can provide.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (7 by maintainers)
@ide I think I was able to get to the bottom of this yesterday. I kept being bothered that I could only ever see v1/tokens be the path in the expo libs I was debugging.I just kept digging around and tying little clues together like I found this phrasing on a stack overflow comment:
âCustomer creation and Charge creation on Stripe is a secret-key only function, therefore cannot be done on your client-side (your mobile app which can only use your publishable key).â
Which made me think, K is it even possible to create a payment/charge? So then started digging around for guides on creating payments/charges and all of them were using node/express but never really said why. Then I found this one: https://enappd.com/blog/stripe-integration-in-react-native-apps-using-firebase/108/ that did an amazing job of explaining things clearly. The below image sums it up.
Basically I think that the misunderstanding was I expected âpaymentRequestWithApplePayAsync / completeApplePayRequestAsyncâ doing âLaunch the  Pay view to accept paymentâ to ACTUALLY make a payment. When in reality all any of those things in the payments library do is make tokens. THEN u have to use node, a firebase cloud function or some other backend to use that token to reach out to stripe yourself to create a payment/charge.
I never found any verbiage on stripe that said outright and clearly why secret-key functions, specifically create charge CANâT be made on the client side and must be made on a backend. I donât see why it would matter and seems a bit odd to me and I gave up looking be I wanted to try things out and see if I could get it working. Iâd love a link to that stripe doc if anyoneâs ever seen it or knows where it exists.
I do think the expo payments library could be way more clear that it is only a token generating tool and cannot actually make payments itself. In my opinion those things should be renamed tokenRequestWithApplePayAsync and the descriptions of them should clearly state that these things will only ever let you make tokens and possibly point future people to some guides that will help them complete the payment.
I personally verified this with the link above, using the firebase and google cloud functions to verify that once you do these things you do actually create a successful PAYMENT in stripe.
Anyway, I hope this sheds more light on what the payments lib in expo does and helps a lost coder out in the future.