В настоящее время я работаю над интеграцией Stripe в мое iOS-приложение с помощью облачных функций Firebase.Я сталкиваюсь со странной проблемой, когда при попытке добавить карту мне сообщается, что мой ключ API отсутствует, когда я определенно настроил его в своих облачных функциях.
Одна вещь, которую я заметил, находится на стороне клиентаесли я не включаю STPPaymentConfiguration (), то код работает правильно, и источник оплаты добавляется в базу данных и полосу.Я что-то здесь упускаю?
Я думаю, что это что-то на внешней стороне, что я не совсем понимаю, потому что с
let addCardViewController = STPAddCardViewController()
мой код работает нормально, и, как должно, но теперьКонтроллер представления не имеет параметров адреса выставления счета.
Мой код быстрого доступа:
@objc func addPaymentPressed(_ sender:UIButton) {
// Setup add card view controller
let config = STPPaymentConfiguration()
config.requiredBillingAddressFields = .full
let addCardViewController = STPAddCardViewController(configuration: config, theme: theme.stpTheme)
//Creating VC without configuration and theme works just fine
//let addCardViewController = STPAddCardViewController()
addCardViewController.delegate = self
let navigationController = UINavigationController(rootViewController: addCardViewController)
navigationController.navigationBar.stp_theme = theme.stpTheme
present(navigationController, animated: true, completion: nil)
}
func addCardViewControllerDidCancel(_ addCardViewController: STPAddCardViewController) {
// Dismiss add card view controller
dismiss(animated: true)
}
func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: @escaping STPErrorBlock) {
dismiss(animated: true)
let cardObject = token.allResponseFields["card"]
print("Printing Strip Token:\(token.tokenId)")
CustomerServices.instance.addPaymentToDB(uid: currentUserId, payment_token: token.tokenId, stripe_id: token.stripeID, cardInfo: cardObject as Any) { (success) in
if success {
print("successfully added card info to subcollection!")
} else {
print("TODO: add error message handler")
}
}
}
Код функции My Cloud:
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const stripe = require('stripe')(functions.config().stripe.token);
const currency = functions.config().stripe.currency || 'USD';
// Add a payment source (card) for a user by writing a stripe payment source token to database
exports.addPaymentSource = functions.firestore
.document('Customers/{userId}/paymentSources/{paymentId}')
.onWrite((change, context) => {
let newPaymentSource = change.after.data();
let token = newPaymentSource.payment_token;
return admin.firestore().collection("Customers").doc(`${context.params.userId}`).get()
.then((doc) => {
return doc.data().customer_id;
}).then((customer) => {
return stripe.customers.createSource(customer, {"source" : token});
});
});
При добавлении конфигурации мне STPAddCardViewController выдает «Вы не предоставили»API-ключ "ошибка.