Paypal MPL for Android and pizza example "Application is not authorized, error identifier is -1"

I downloaded this library: MPL

I downloaded this example: PizzaMPL

I created a sandbox account and several personal and business accounts.

I see the API credentials and signature perfectly (I don’t need the API credentials for testing in SANDBOX?) If so, where do I need to paste my code? The docs say, “In addition to the API credentials, MPL calls also require an AppID. For Sandbox in PayPal, the AppID is static:“ APP-80W284485P519543T ”“ In the app <? >

Now in the SANDBOX environment, when I give the "pay using PayPal" button, the code received in PayPalActivityResult (int requestCode, int resultCode, intention intent): PayPal.FAILURE and the displayed message: "The application is not authorized, Error ID -1"

I could not find this error in the wonderful PayPal documentation.

Here is my code:

public void initLibrary() {
    PayPal pp = PayPal.getInstance();

    if (pp == null) {            
        pp = PayPal.initWithAppID(this, "APP-80W284485P519543T",
                PayPal.ENV_SANDBOX);

        pp.setLanguage("en_US");
        pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
        pp.setShippingEnabled(true);
        pp.setDynamicAmountCalculationEnabled(false);
        _paypalLibraryInit = true;
    }
}

private void showPayPalButton() {

    // Generate the PayPal checkout button and save it for later use
    PayPal pp = PayPal.getInstance();
    CheckoutButton launchPayPalButton = pp.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);
    // The OnClick listener for the checkout button
    launchPayPalButton.setOnClickListener(this);
    // Add the listener to the layout
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams (ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params.bottomMargin = 10;
    launchPayPalButton.setLayoutParams(params);
    launchPayPalButton.setId(12345);
    ((LinearLayout) findViewById(R.id.wrapper)).addView(launchPayPalButton);
    ((LinearLayout) findViewById(R.id.wrapper)).setGravity(Gravity.CENTER_HORIZONTAL);
}


public void PayPalButtonClick(View arg0) {
    // Create a basic PayPal payment
    PayPalPayment payment = new PayPalPayment();
    payment.setCurrencyType("USD");        
    payment.setRecipient("erauskin-facilitator@gmail.com");        
    payment.setSubtotal(new BigDecimal(200.0f));        
    payment.setPaymentType(PayPal.PAYMENT_TYPE_PERSONAL);        
    payment.setMerchantName("Discográfica XXX");        
    Intent paypalIntent = PayPal.getInstance().checkout(payment, this);
    this.startActivityForResult(paypalIntent, 1);
}

public void PayPalActivityResult(int requestCode, int resultCode, Intent intent) {
        switch (resultCode) {
        case Activity.RESULT_OK:
            // The payment succeeded
            String payKey = intent
                    .getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
            this.paymentSucceeded(payKey);
            break;
        case Activity.RESULT_CANCELED:
            // The payment was canceled
            this.paymentCanceled();
            break;
        case PayPalActivity.RESULT_FAILURE:
            // The payment failed -- we get the error from the
            // EXTRA_ERROR_ID and EXTRA_ERROR_MESSAGE
            String errorID = intent
                    .getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
            String errorMessage = intent
                    .getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
            this.paymentFailed(errorID, errorMessage);
        }
}
+4
source share

Source: https://habr.com/ru/post/1539537/


All Articles