Created
July 30, 2015 15:10
-
-
Save a2f0/fbe39890a3578f169ad7 to your computer and use it in GitHub Desktop.
braintree tokenizecard js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client.tokenizeCard({ | |
number: $scope.ngTransaction.$transaction.cc, | |
cardholderName: cardholdername, | |
// You can use either expirationDate | |
expirationDate: "10/20", | |
// or expirationMonth and expirationYear | |
//expirationMonth: "10", | |
//expirationYear: "2015", | |
// CVV if required | |
//cvv: "832", | |
cvv: "111", | |
// Address if AVS is on | |
billingAddress: { | |
postalCode: "94107" | |
} | |
}, function (err, nonce) { | |
console.log("Send nonce to server."); | |
console.log("nonce " + nonce); | |
console.log("error:" + err); | |
myData.nonce = nonce | |
var req = { | |
method: 'POST', | |
url: '/swag/confirmjs.json', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
data: myData | |
} | |
/* | |
data: { nonce: nonce, | |
cart: [ {"id":1,"name":"John Doe"}, | |
{"id":2,"name":"Don Joeh"} ], | |
rendered: angular.toJson(ngCart.getNewItems()), | |
rendered2: JSON.stringify(ngCart.getNewItems()) | |
} | |
*/ | |
$http(req).success(function(data, status, headers, config){ | |
console.log("success"); | |
console.log("RESPONSE STATUS: " + status); | |
console.log("RESPONSE DATA: " + JSON.stringify(data)); | |
//alert(typeof success); | |
//alert(typeof data['success']); | |
console.log("SUCCESS2:" + data['success']) + "end"; | |
//console.log("jsonObj.success: " + jsonObj.success); | |
//console.log("SUCCESS: " + data['success']); | |
if ( data['success'] == true) { | |
console.log("TRUE" + data['success']); | |
console.log("ID:" + data['successful']['id']); | |
$location.path('/swag/angularswag/thankyou'); | |
$scope.ngCompleteTransaction.id = data['successful']['id']; | |
} else if ( data['success'] == false) { | |
console.log("FALSE:" + data['success']); | |
//Then we have found validation errors | |
if (typeof data['errors'] !== 'undefined') { | |
console.log("ERROR Length: " + data['errors'].length); | |
for (var i = 0; i < data['errors'].length; i++) { | |
console.log("error: " + data['errors'][i][0]); | |
console.log("message: " + data['errors'][i][0]); | |
//$scope.ngTransaction.$validationerrors[data['errors'][i][0]] = data['errors'][i][1]; | |
console.log("setting key: " + data['errors'][i][0]); | |
$scope.ngTransaction.$validationerrors[data['errors'][i][0]] = data['errors'][i][1]; | |
} | |
} | |
} else { | |
console.log("ELSE:" + data['success'] + "end"); | |
} | |
$scope.ngTransaction.id | |
}).error(function(data, status, headers, config){ | |
console.log("error"); | |
}); | |
}); | |
console.log("Finsished processtransaction"); | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment