Данные не могут быть прочитаны, потому что они не в правильном формате Stripe - PullRequest
0 голосов
/ 14 апреля 2020

Я пытаюсь создать StripeEphemeralKeys в своем приложении IOS, используя Stripe и Firebase, но я продолжаю получать эту ошибку, когда пытаюсь распечатать данные. The data couldn’t be read because it isn’t in the correct format. Я не могу понять, почему!

Функции:

exports.createStripeEphemeralKeys = functions.https.onCall((data, context) => {
const customerId = data.customerId;
const stripe_version = data.stripe_version;
return stripe.ephemeralKeys
    .create({
        customer: customerId,
        stripe_version: stripe_version
    })
});

Представление:

func choosePaymentButtonTapped() {

    guard let uid = Auth.auth().currentUser?.uid else { return }

    var paymentContext: STPPaymentContext?

    let ref = Database.database().reference().child("stripe_customers").child(uid)
    ref.observeSingleEvent(of: .value) { (snapshot) in

        guard let dict = snapshot.value as? [String: Any] else { return }
        guard let customerId = dict["customer_id"] as? String else { return }

        let customerContext = STPCustomerContext(keyProvider: StripeProvider(customerId: customerId))
        paymentContext = STPPaymentContext(customerContext: customerContext)
        paymentContext!.delegate = self
        paymentContext!.hostViewController = self
        paymentContext!.presentPaymentOptionsViewController()
    }
}

Stripe API:

class StripeProvider: NSObject, STPCustomerEphemeralKeyProvider {
lazy var functions = Functions.functions()
let customerId: String

init(customerId: String){
    self.customerId = customerId
}

func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
    let data: [String: Any] = [
        "customerId": customerId,
        "stripe_version": apiVersion
    ]
    functions
        .httpsCallable("createStripeEphemeralKeys")
        .call(data) { result, error in

            if let error = error {
                print(error.localizedDescription)
                completion(nil, error)
            } else if let data = result?.data as? [String: Any] {
                completion(data, nil)
            }
    }
}
}

1 Ответ

0 голосов
/ 14 апреля 2020

Похоже, onCall возвращает структуру данных, отличную от ожидаемой: https://firebase.google.com/docs/functions/callable-reference

Я думаю, что вы можете использовать onRequest вместо: https://firebase.google.com/docs/functions/http-events#using_express_request_and_response_objects

...