Cordova plugin for PayPal with MPL SDK (Mobile Payment Library, not new SDK)
npm install cordova-plugin-paypalmplIt's for PayPal classic library MPL (Mobile Payment Library), not for new PayPal SDK. As it's stated by PayPal, new SDK is only available for US currently, not for other country yet. The SDK can be downloaded from PayPal website, or just clone to get some common used SDK:
https://github.com/floatinghotpot/mobile-sdk.git
cordova plugin add https://github.com/floatinghotpot/cordova-plugin-paypalmpl.git
Check the README.md in sub folder for details.
function onDeviceReady() {
document.addEventListener('PaypalPaymentEvent.Success',function(){
alert('game coins purchased, enjoy gaming.');
});
document.addEventListener('PaypalPaymentEvent.Failed',function(){
alert('sorry that payment failed, please try again later.');
});
if( window.plugins && window.plugins.PayPalMPL ) {
var ppm = window.plugins.PayPalMPL;
var isTesting = false;
var appID = isTesting ? 'APP-80W284485P519543T' : 'APP-0HN45655HA567492N';
var appEnv = isTesting ? ppm.PaymentEnv.ENV_SANDBOX : ppm.PaymentEnv.ENV_LIVE;
ppm.initWithAppID( {
'appId': appID,
'appEnv': appEnv,
}, function(){
window.plugins.PayPalMPL.isReady = true;
}, function(){
});
}
}
function buyGameCoin( n ) {
if( window.plugins && window.plugins.PayPalMPL ) {
var ppm = window.plugins.PayPalMPL;
ppm.setPaymentInfo({
'lang' : 'en_US',
'paymentType' : ppm.PaymentType.TYPE_GOODS,
'showPayPalButton': -1,
'paymentCurrency' : 'USD',
'subTotal' : 1.99,
'recipient' : 'rjfun.mobile@gmail.com',
'description' : 'game coins (' + n + ')',
'merchantName' : 'rjfun'
}, function() {
ppm.pay({}, function() {
// alert( 'paypal pay done' );
}, function() {
alert('paypal pay failed');
});
}, function() {
alert('paypal setPaymentInfo failed');
});
} else {
alert( 'PayPalMPL plugin not loaded.' );
}
}