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
I'm stuck on this issue:
When I try to submit this subscription, I got an error of "subscription_payment_intent_requires_action", should I handle it on client side or there is another way to do it?
Thank you all!
// Create Subscription With Payment Method + Customer ID
router.post('/createSubscription', function (req, res){
const {payment_method, customerId} = req.body;
var stripe = require("stripe")(stripe_sk);
try{
stripe.subscriptions
.create({
customer: customerId,
items: [{
plan: 'plan_HTGCI8ljPYFTHQ'
}],
default_payment_method: payment_method,
expand: ["latest_invoice.payment_intent"],
// enable_incomplete_payments: true
}).then(subscription => {
res.send({
subscription : subscription
})
}).catch(err => {
res.send({
err
})
})
} catch (error) {
res.send("Error : ", error);
}
});