How to integrate paypal into an Android app using webview

I want to integrate paypal in my applications. I was close to getting there before I saw this: https://developer.paypal.com/webapps/developer/support/faq#non-US-dev Paypal does not allow a non-US developer to use the REST API. So the choice I left is the classic api. This is where the problem is. I do not know how to use them.

I plan to use the NVP api. I have no idea how to do this, but below is my flowchart of how I plan to do this. I need to set the item number, description, price, etc. On checkout.java, which will send to www.domain.com/setsessions.php

I'm not sure if this will work. But even if it’s possible, I wonder how the new “intention” detects whether the user successfully made the payment, refused the payment, or canceled the payment.

App paypal flow

I need help. This is really frustrating ... we tried to integrate paypal for almost two weeks. Feel so unproductive.

Is that even normal? Or is there a better method? My requirement is to set the account number, no, description, price, location, all this is required from the application.

+4
source share
1 answer

MainActivity.java

public class PizzaMain extends Activity implements OnClickListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PayPal ppObj = PayPal.initWithAppID(this.getBaseContext(), "APP-80W284485P519543T", PayPal.ENV_NONE); CheckoutButton launchPayPalButton = ppObj.getCheckoutButton(this, PayPal.BUTTON_152x33, CheckoutButton.TEXT_PAY); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.CENTER_HORIZONTAL); launchPayPalButton.setLayoutParams(params); launchPayPalButton.setOnClickListener(this); ((RelativeLayout) findViewById(R.id.mRlayout1)).addView(launchPayPalButton); } @Override public void onClick(View v) { // TODO Auto-generated method stub PayPalPayment newPayment = new PayPalPayment(); char val[] = { '5', '0' }; BigDecimal obj_0 = new BigDecimal(val); newPayment.setSubtotal(obj_0); newPayment.setCurrencyType("USD"); newPayment.setRecipient(" my@email.com "); newPayment.setMerchantName("My Company"); Intent paypalIntent = PayPal.getInstance().checkout(newPayment, this); this.startActivityForResult(paypalIntent, 1); } @SuppressWarnings("unused") @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (resultCode) { case Activity.RESULT_OK: // The payment succeeded String payKey = data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY); // Tell the user their payment succeeded break; case Activity.RESULT_CANCELED: // The payment was canceled // Tell the user their payment was canceled break; 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); // Tell the user their payment was failed. break; } } } 

And give below permission to your AndroidManifest.xml file.

 <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> 

And add Activity to your AndroidManifest.xml file.

 <activity android:name="com.paypal.android.MEP.PayPalActivity" android:configChanges="keyboardHidden|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> 

Add the PayPal_MPL.jar Jar file as a reference library to your application

+5
source

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


All Articles