Giter Site home page Giter Site logo

sanjinl / cordova-plugin-paypalmpl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from covernal/cordova-plugin-paypalmpl

0.0 0.0 0.0 7.96 MB

Cordova Plugin for PayPal MPL Library, not for new SDK.

License: MIT License

Java 34.24% Objective-C 35.88% HTML 9.94% JavaScript 19.94%

cordova-plugin-paypalmpl's Introduction

PayPalMPL Plugin


Can support PayPal in cordova/phonegap app? Yes, you can!

This is the PayPal Cordova Plugin for Android and iOS. It provides a way to request PayPal natively from JavaScript. This plugin was updated for Cordova 3.0.0, and tested with the PayPal MPL iOS 2.0.1/Android 1.5.5.45 SDK.

It'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

How to use?


To install this plugin, follow the Command-line Interface Guide.

cordova plugin add https://github.com/floatinghotpot/cordova-plugin-paypalmpl.git

Check the README.md in sub folder for details.

How to use it in javascript


    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' : '[email protected]',
        		'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.' );
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.