Parse.com create stripe card token in cloud code (main.js)

安稳与你 提交于 2019-12-02 11:08:23

Finally my research is over and I got the solution:

Parse.Cloud.httpRequest({
    method : 'POST',
    url : 'https://api.stripe.com/v1/tokens',
    headers : {
        'Authorization' : 'Bearer sk_test_xxxxxxxxxxxxxx'
    },
    body : {
        "card[number]" : request.params.number,
        "card[exp_month]" : request.params.month,
        "card[exp_year]" : request.params.year,
        "card[cvc]" : request.params.cvc
    },
    success : function(httpResponse) {
        token = httpResponse.data.id; // Its token which required for create payment/charge
    },
    error : function(httpResponse) {
        // Error
    }
})

The above code can be used in any cloud function which are written in main.js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!