Как правильно настроить полосовую подписку с Android / Node.js? - PullRequest
0 голосов
/ 16 апреля 2020

Мне интересно, как правильно настроить полосовую подписку. Код, который у меня есть, приведен ниже. Я на правильном пути? Это не похоже на работу.

FirebaseFunctions.getInstance() 
    .getHttpsCallable("createSubscription")
    .call()
    .addOnFailureListener {      
    }
    .addOnSuccessListener {
    }

В node.js:

exports.createSubscription = functions.https.onRequest(async (request, response) => {
    try {
        const snapshot = await admin.database().ref().child('stripe_customers').child(context.params.userId).once('value')
        const snapval = snapshot.val();
        const customer = snapval.customer_id
        // List the customer's payment methods to find one to charge
        const paymentMethods = await stripe.paymentMethods.list({
            customer,
            type: "card"
        });
        // Create and confirm a PaymentIntent with the order amount, currency, 
        // Customer and PaymentMethod ID

        let paymentIntent = stripe.subscriptions.create(
  {
    customer: customer,
    items: [{plan: 'plan_H6AaFZ3wK18rAB'}],
  },
  function(err, subscription) {
    // asynchronously called
  }
);
    } catch (err) {
        console.log("Unknown error occurred", err);
    }
});


Примечание. Я настраиваю пользователей и правильно собираю платежную информацию, и они могут выбрать карту по умолчанию, так что это не та часть, которую я Я обеспокоен

...