簡體   English   中英

使用節點 js 以條帶形式進行匯款和訂閱工作流程

[英]Money transfer and subscribe workflow in stripe using node js

我對 Stripe 完全陌生,我們將其用作我們的支付網關。 我想知道如何將錢從我的客戶信用轉移到我的 Stripe 帳戶以及如何使用 nodeJs 使用訂閱。

我在 node.js 應用程序上的付款功能

function pay( number, exp_month, exp_year, cvc){            
            let stripeAmount: 1
            const card = {
                number,
                exp_month,
                exp_year,
                cvc
            }

            let chargeIdToRefund

            const payment = await stripe.tokens
                .create({
                    card
                })
                .then((token) =>
                    stripe.customers.create({
                        email,
                        source: token.id
                    })
                )
                .then((customer) =>
                    stripe.charges.create({
                        amount: stripeAmount,
                        currency: 'usd',
                        customer: customer.id
                    })
                )
                .then((charge) => {
                    chargeIdToRefund = charge.id
                    return Payment.create({
                        user_id,
                        amount: stripeAmount
                    })
                })
                .then(async (payment) => {
                    if (payment) { ... } else throw { charge: chargeIdToRefund }
                }).catch(async (err) => {
                    if (err.charge)
                        return await stripe.refunds
                            .create({
                                charge: err.charge
                            })
                            .then((refund) => {
                                if (refund.status === 'succeeded'){ ... }
                            })
                    else return err.message
                })
}

您可以按照指南通過結帳接受付款或在您自己的網站上使用Elements來完成此操作。

如果您在解決此問題時有更具體的問題,請更新您的問題並發表評論以進行澄清。

暫無
暫無

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

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