Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Make payment using PayPal MPL(Mobile Payment Libraries) in Android

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.16k
    Comment on it

    There are certain applications in which we need to integrate the PayPal for enabling the user to pay certain amount to use further features of the app.

    Before starting, download the PayPal_MPL.jar file from PayPal developer's website and copy same in project's libs. Also, add the PayPal activity in manifest like:


    Below is the code that's all required to make payment easily:

    I've used following code in the onCreate() method of the Activity. The "paypalBtn" used below initiates the Payment call.

     Button paypalBtn = (RelativeLayout)findViewById(;
        PayPal ppObj = PayPal.initWithAppID(this.getBaseContext(), "your app id from", PayPal.ENV_LIVE);
        CheckoutButton launchPayPalButton = ppObj.getCheckoutButton(this, PayPal.BUTTON_194x37, CheckoutButton.TEXT_PAY);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        launchPayPalButton.setOnClickListener(new OnClickListener() {           
            public void onClick(View v) {
                PayPalPayment newPayment = new PayPalPayment();
                char val[] = { '9', '9' };
                BigDecimal obj_0 = new BigDecimal(val);
                Intent paypalIntent = PayPal.getInstance().checkout(newPayment, confirmSubscription);
                startActivityForResult(paypalIntent, 1);                
        ((RelativeLayout) findViewById(;

    I'm making a payment of USD 99 in above code. Also, in initWithAppID() method at the beginning, you can set the payment environment to sandbox by using PayPal.ENV_SANDBOX in place of PayPal.ENV_LIVE and use APP-80W284485P519543T as the app id. The following code overrides the onCreate() method of Activity and looks for the result of payment request that we made above,

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (resultCode) {
        case Activity.RESULT_OK:
            // The payment succeeded
            payKey = data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
            System.out.println("Result Ok: Paykey is:: "+payKey);
            // Tell the user their payment succeeded
        case Activity.RESULT_CANCELED:
            System.out.println("Result Cancelled!!!!");
            // The payment was canceled
            // Tell the user their payment was canceled
        case PayPalActivity.RESULT_FAILURE:
            // The payment failed -- we get the error from the EXTRA_ERROR_ID
            // and EXTRA_ERROR_MESSAGE
            String errorID = data.getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
            String errorMessage = data.getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
            System.out.println("Result Failure!!!!");
            System.out.println("Result Failure:: Error Id!!!!"+errorID);
            System.out.println("Result Failure:: Error Message!!!!"+errorMessage);
            // Tell the user their payment was failed.

    Hope it makes you make your first payment :)

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: