簡體   English   中英

stripe js 創建一個客戶

[英]stripe js create a customer

我需要使用他們的 JS 客戶端在 Stripe 上創建一個新客戶。

我似乎無法找到創建它的方法,

這是我的代碼:

<script src="https://js.stripe.com/v3/"></script>

在頁面中加載腳本

然后在我的 js 文件中:

我有:

const stripe = Stripe(App.Config.stripeKey);

function createCustomer(){
    return Stripe.customers.create({email: $('#payment-form').data('email')}).then(function(result) {
        if (result.error) {
            const errorElement = document.getElementById('card-errors');
            errorElement.textContent = result.error.message;
            return new Promise((resolve, reject) => {
                reject(result.error.message);
            });
        } else {
            stripeCustomerTokenHandler(result.token);
            return new Promise((resolve, reject) => {
                resolve(result.token);
            });
        }
    })
}

我也嘗試過stripe.customers.create({...} (即使用 Stripe 對象) 但在這兩種情況下我都得到Uncaught TypeError: Cannot read property 'create' of undefined

有任何想法嗎?

Stripe.js 具有許多特性和功能,包括安裝卡元素和使用可發布密鑰確認付款,但它不用於直接尋址 API。

調用 API 以執行諸如創建客戶或 PaymentIntent 之類的操作,必須使用您的密鑰從后端完成。 您的前端可以使用 RESTful 調用與后端服務器交互,后者又可以調用 API 以從服務器創建客戶。 例如,在節點中,您的后端可以使用此調用 [1]。

const stripe = require('stripe')('sk_test_xxx');

const customer = await stripe.customers.create({
  description: 'My First Test Customer (created for API docs)',
});

可以在此處查看說明使用后端代碼和 Stripe.js 來確認付款的集成示例 [2]。

[1] https://stripe.com/docs/api/customers/create?lang=node

[2] https://stripe.com/docs/payments/accept-a-payment?integration=elements

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM