crunchbutton/www/assets/js/tokenizeCard.balanced.js
Daniel Camargo 518f302ebb partial #2243 - add the ability to pay using stripe or balanced in the order.php
Updated the Stripe API (php) to the new version (from 1.7.2 to 1.10.1).

Updated the keys (public and secret) of the test env (config.xml). I was afraid to change it from the live one.

I changed the way the user_payment_type was working.
Now the user will be able to have two actives payment types, one for stripe and another for balanced.

When you call the method Crunchbutton_User_Payment_Type::getUserPaymentType() it will return the active payment type for the current processor.

I have also created this method Crunchbutton_User_Payment_Type::processor() returns the current processor type and replaced all the calls from c::config()->processor to this method. That way if we decide to put this data at config’s table we will have to just change this method. Or even is we need to use the processor type that is previously stored that will be easy too.

I created two new files tokenizeCard.stripe.js and tokenizeCard.balanced.js and moved the method App.tokenizeCard to these files
2013-12-18 14:43:22 -02:00

56 lines
1.2 KiB
JavaScript

App.tokenizeCard = function(card, complete) {
balanced.card.create(card, function(response) {
var res = {
status: false
};
switch (response.status) {
case 201:
res.status = true;
res.id = response.data.id;
res.uri = response.data.uri;
res.card_type = response.data.card_type;
res.lastfour = response.data.last_four;
res.month = card.expiration_month;
res.year = card.expiration_year;
break;
case 400:
res.error = 'Missing fields';
break;
case 402:
res.error = 'Unable to authorize';
break;
case 404:
res.error = 'Unexpected error';
break;
case 409:
res.error = 'Unable to validate';
break;
case 500:
res.error = 'Error processing payment';
break;
// a lack of any response from the ios sdk
case 999:
res.error = 'Unable to reach payment server';
break;
// a response from the ios sdk that was both ilformated and didnt not validate
case 666:
res.error = 'Unable to validate your card';
break;
// who knows wtf this is
default:
res.error = 'Unable to validate your card at this time';
break;
}
console.debug('Balanced tokenization response',response);
complete(res);
} );
};