LoginSignup
0
0

More than 5 years have passed since last update.

stripeでephemeralKeysを作るときにエラーになった話

Posted at

先日書いた「Firebase + stripe + iOS」でクレジットカード決済機能を作るにおいて、

以下のようなワンタイムトークンを作るメソッドがあったのですが、

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
        })
});

cloud functionsは一回のリクエストにも関わらず何回も実行することがあるという話を聞いて、安全のためにPassing Optionsに書いてあるidempotency_keyをつけることにしました。

以下のような感じ。

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
        }, { idempotency_key: data.idempotencyKey })
});

そしたらstripeでエラーを吐くようになってしまいました。

スクリーンショット 2019-06-10 11.55.19.png

慌ててidempotency_keyを外したりしてみたが、どうにもエラーがとまりませんでした。

結局

以下のような書き方で解決しました。Passing Optionsに関しては、createの2つ目の引数に書いた方がいいみたいです。(TypeScripte, node.jsの知識足りない)

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,
                idempotency_key: data.idempotencyKey
            })
});

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0