付款选项视图控制器(用于条带)未显示

时间:2020-08-20 23:13:41

标签: node.js firebase google-cloud-functions

我对此很陌生。我已经使用云功能和Firebase将Stripe集成到我的iOS项目中。这是我有关付款选项的代码(在node.js中)。

exports.addPaymentMethodDetails = functions.firestore
.document('/stripe_customers/{userId}/payment_methods/{pushId}')
.onCreate(async (snap, context) => {
try {
  const paymentMethodId = snap.data().id;
  const paymentMethod = await stripe.paymentMethods.retrieve(
    paymentMethodId
  );
  await snap.ref.set(paymentMethod);
  // Create a new SetupIntent so the customer can add a new method next time.
  const intent = await stripe.setupIntents.create({
    customer: paymentMethod.customer,
  });
  await snap.ref.parent.parent.set(
    {
      setup_secret: intent.client_secret,
    },
    { merge: true }
  );
  return;
} catch (error) {
  await snap.ref.set({ error: userFacingMessage(error) }, { merge: true });
  await reportError(error, { user: context.params.userId });
}
})

这是我在Xcode中的代码:

 ``let customerContext = STPCustomerContext(keyProvider: StripeApi)

 var paymentContext: STPPaymentContext!

init() {
    self.paymentContext = STPPaymentContext(customerContext: customerContext)
    super.init(nibName: nil, bundle: nil)
    self.paymentContext.delegate = self
    self.paymentContext.hostViewController = self
    self.paymentContext.paymentAmount = 5000 // This is in cents, i.e. $50 USD
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}



@IBAction func paymentMethodClicked(_ sender: Any) {
    
    paymentContext.pushPaymentOptionsViewController()
        
    }

    
func setupStripeConfig() {
        let config = STPPaymentConfiguration.shared()
        config.additionalPaymentOptions = .default
        config.requiredBillingAddressFields = .none
        
        let customerContext = STPCustomerContext(keyProvider: StripeApi)
        paymentContext = STPPaymentContext(customerContext: customerContext, configuration: config, theme: .default())
        
    paymentContext.delegate = self
    paymentContext.hostViewController = self

当我运行它的模拟器并单击按钮以调出付款选项时,什么也没有发生,并且我的控制台(在Xcode中)显示为“ INTERNAL”。有人可以告诉我如何启动“付款选项视图控制器”,或者是否需要执行某些操作或添加/修复此操作?这也是我的用于获取临时密钥的node.js代码:

exports.createEphemeralKey = functions.https.onCall(async (data, context) => {
const customerID = data.customer_id;
const stripeVersion = data.stripe_version;
const uid = context.auth.uid;

if (uid === null) {
console.log('Illegal access attempt due to unauthenticated user');
throw new functions.https.HtppsError('permission-denied', 'Illegal access attempt')

}
let key = await stripe.ephemeralKeys.create(
{customer: '{{CUSTOMER_ID}}'},
{stripe_version: '{{API_VERSION}}'}
);

return stripe.ephemeralKeys.create(
{customer: customerID},
{stripe_version: stripeVersion}).then((key) => {
  return key
}).catch((err) => {
  console.log(err)
  throw new functions.https.HttpsError9('internal', 'Unable to create ephemeral key.')
});
});

0 个答案:

没有答案