0

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 dont want to expose my Stripe.setPublishableKey('pk_test_xxxxxxx');

Because of this reason interest to define function in cloud code.

Parse.Cloud.define("addCreditCard", function(request, response) {
    var token;
    var group;

    var Stripe = require('https://js.stripe.com/v2/');
    Stripe.setPublishableKey('pk_test_xxxxxxxxx');

    Stripe.card.createToken({
        number : request.params.number,
        cvc : request.params.cvc,
        exp_month : request.params.month,
        exp_year : request.params.year
    }, {
        sucsess: function(result) { response.success("Ok"); },
        error : function(error) { response.error(error); }
    });
});

Here parse cloud unable to call var Stripe = require('https://js.stripe.com/v2/');

If so many place suggested use parse cloud stripe module var Stripe = require('stripe'); var STRIPE_SECRET_KEY = 'sk_test_xxxxxxxxxx';

But here the function Stripe.card.createToken is not define

rici
  • 234,347
  • 28
  • 237
  • 341
Neelabh
  • 19
  • 1
  • try using Stripe.tokens.create instead of Stripe.cart.createToken? https://stripe.com/docs/api#token_object – Alex Dec 27 '14 at 03:48
  • No such method createToken i am refering https://www.parse.com/docs/js/symbols/Stripe.Tokens.html – Neelabh Dec 27 '14 at 03:58
  • Why don't you want to expose your publishable key? It's totally safe as explained here: https://support.stripe.com/questions/difference-between-secret-key-and-publishable-key Doing what you plan will require the card details to reach your server and you would have to be PCI compliant on your own which is a lot of work – koopajah Dec 27 '14 at 09:53
  • I want to minimize the client side things and plan most of the things in cloud function.. Because client side source code is exposed – Neelabh Dec 27 '14 at 11:16

1 Answers1

1

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

Neelabh
  • 19
  • 1
  • As someone else said, this will require you to be pci compliant. This goes far beyond everything being behind SSL – Alex Dec 27 '14 at 11:28
  • In anycase if we are taking payment information at our page we required PCI compliant certificate and SSL.. Otherwise we have to redirect on payment gateway page because those are PCI compliant.. – Neelabh Dec 27 '14 at 12:00
  • Not actually totally correct. If you were using stripe as intended, sensitive credit card details are never passed to the server, so never leave the client, therefore negate the need for pci compliance – Alex Dec 27 '14 at 14:14