#node.js #firebase #google-cloud-functions
#node.js #firebase #google-cloud-функции
Вопрос:
Я довольно новичок в этом. Я использовал облачные функции и 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) считывает «ВНУТРЕННЯЯ». Может кто-нибудь, пожалуйста, показать мне, как вызвать контроллер просмотра параметров оплаты, или если есть что-то, что мне нужно добавить / исправить, чтобы сделать это? Также вот мой 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.')
});
});
Комментарии:
1. Где журнал? (Для вашего JS-кода)
2. Я действительно нашел ответ, но спасибо за помощь!
3. Если вы нашли ответ, рассмотрите возможность обновления вопроса, чтобы включить его для будущих читателей с аналогичной проблемой