Skip to content

Instantly share code, notes, and snippets.

@ademcan
Created June 21, 2020 11:08
Show Gist options
  • Save ademcan/a2e86c7eaa6936aad78ff5f7a3f47929 to your computer and use it in GitHub Desktop.
Save ademcan/a2e86c7eaa6936aad78ff5f7a3f47929 to your computer and use it in GitHub Desktop.
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
})
});
})
@hamzaDv
Copy link

hamzaDv commented Jun 22, 2020

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