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

前端 未结 1 1247
再見小時候
再見小時候 2021-01-28 04:01

I am looking to create stripe token in parse cloud code..

I dont want to create token in client side HTML page. My complete web application is in HTML + Javascript so do

相关标签:
1条回答
  • 2021-01-28 04:17

    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

    0 讨论(0)
提交回复
热议问题