Created
June 21, 2020 11:08
-
-
Save ademcan/a2e86c7eaa6936aad78ff5f7a3f47929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.post('/createStripeCustomer', function (req, res) { | |
var stripe = require("stripe")(stripe_sk); | |
var payment_method = req.body.payment_method | |
var name = req.body.name // optional | |
var email = req.body.email // optional | |
// This creates a new Customer and attaches the PaymentMethod in one API call. | |
stripe.customers.create({ | |
payment_method: payment_method, | |
name: name, | |
email: email | |
}, function (err, customer) { | |
res.json({ | |
customer: customer.id | |
}) | |
}); | |
}) |
Where I am now:
Subscription created with status "incomplete".
So what I have to do is to convert this code to react-native (objective C)
function manageSubscriptionStatus(subscription) {
const { latest_invoice } = subscription;
const { payment_intent } = latest_invoice;
if (payment_intent) {
/* Do NOT share or embed your client_secret anywhere */
const { client_secret, status } = payment_intent;
if (status === "requires_action" || status === "requires_payment_method") {
stripe.confirmCardPayment(client_secret) // **Which stripe-ios function does the same treatment to generate authentification**
.then((result) => {
if (result.error) {
showState('payment-form');
displayError(result.error); // Display error message to customer
} else {
showState('success'); // Show success state
}
}).catch((err) => {
console.error('Error confirming card payment:', err);
showState('error'); // Show error state
});
} else {
showState('success'); // Show success state
}
} else {
/* If no payment intent exists, show the success state
* Usually in this case if you set up a trial with the subscription
*/
showState('success');
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This thread might be helpful: https://stackoverflow.com/questions/57318152/stripe-subscriptions-charing-a-3d-secure-card-number-returning-subscription-pa