Plugin to use native Braintree SDK within PhoneGap framework projects
- Add
iOSBraintreePhoneGapPlugin.[h|m]
to your project (Plugins group). - Copy
BrainTreePayment.js
to your project'swww
folder - Add the following to your
config.xml
:
<plugin name="BraintreePlugin" value="iOSBraintreePhoneGapPlugin" />
function callWebService(){
var BTPayment = window.plugins.btreeplugin;
BTPayment.getCardInfo(onGetCardInfoSuccess,onGetCardInfoError);
function onGetCardInfoSuccess (successObject) {
var cardData;
// Verifying is we got encrypted card infor or token
//
if (successObject.cardInfoEncrypted) {
cardData = successObject.cardInfoEncrypted;
} else if (successObject.token) {
cardData = successObject.token;
} else {
// do something
}
// Communicating with the remote server
//
$.post("your endpoint", cardData, function(data) {
console.log('server returned sucess' + JSON.stringify(data));
// Received response from Braintree servers
// now can dismiss the view
BTPayment.dismiss();
};
function onGetCardInfoError (errorObject) {
console.log('onGetCardInfoError: ' + errorObject);
};
}
If you use PhoneGap's tools to generate project you may need to enable ARC in build settings if you experienced crash when trying to enter credit card number