Skip to content

Instantly share code, notes, and snippets.

@ajsharp
Created October 18, 2013 18:02
Show Gist options
  • Select an option

  • Save ajsharp/7045535 to your computer and use it in GitHub Desktop.

Select an option

Save ajsharp/7045535 to your computer and use it in GitHub Desktop.
.. container:: tab-content
.. container:: tab-pane active
:name: tokenize-js
.. code-block:: javascript
var callback = function(response) {
switch (response.status) {
case 201:
// Persist the card on your server with the card uri
$.ajax({
url: '/cards',
data: {card: {uri: response.data['uri']}}
})
break;
case 400:
// missing field - check response.error for details
console.log(response.error);
break;
case 402:
// we couldn't authorize the buyer's credit card
// check response.error for details
console.log(response.error);
break;
case 404:
// your marketplace URI is incorrect
console.log(response.error);
break;
case 500:
// Balanced did something bad, please retry the request
break;
}
}
var $form = $('#credit-card-form');
var creditCardData = {
card_number: $form.find('.cc-number').val(),
expiration_month: $form.find('.cc-em').val(),
expiration_year: $form.find('.cc-ey').val(),
security_code: $form.find('.cc-csc').val()
};
balanced.card.create(creditCardData, callback)
.. container:: tab-pane
:name: tokenize-ios
.. code-block:: objective-c
Balanced *balanced = [[Balanced alloc] initWithMarketplaceURI:@"/v1/marketplaces/TEST-MP6E3EVlPOsagSdcBNUXWBDQ"];
BPCard *card = [[BPCard alloc] initWithNumber:@"4242424242424242" expirationMonth:8 expirationYear:2025 securityCode:@"123"];
[balanced tokenizeCard:card onSuccess:^(NSDictionary *responseParams) {
// success
} onError:^(NSError *error) {
// failure
}];
.. container:: tab-pane
:name: tokenize-android
.. code-block:: javascript
Balanced balanced = new Balanced(marketplaceURI, context);
Card card = new Card("4242424242424242", 9, 2014, "123");
String cardURI = "";
Card card = new Card("4242424242424242", 9, 2014, "123");
Balanced balanced = new Balanced(marketplaceURI, context);
try {
cardURI = balanced.tokenizeCard(card);
}
catch (CardNotValidatedException e) {
error = e;
}
catch (CardDeclinedException e) {
error = e;
}
catch (Exception e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment