1. The document provides steps to integrate PayPal payments for mobile applications. It describes adding the PayPal library files, initializing the library with an app ID and environment, creating a PayPal payment object, and handling the payment response.
2. Key steps include adding permissions to the app manifest, initializing the library with a sandbox or live app ID, creating a PayPalPayment object with payment details, and starting the PayPal activity.
3. The onActivityResult callback handles the payment response, indicating if it succeeded, was canceled, or failed along with associated error information.
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Integrate PayPal Mobile Payment in 5 Steps
1. “iOS and Android Mobile application Development Company in India” www.letsnurture.com
How to Integrate Paypal for Mobile
Payment
2. “iOS and Android Mobile application Development Company in India” www.letsnurture.com
Integrate Paypal for Mobile Payment
Follow Simple steps describe below.
Note:
1. include PayPal_MPL.jar in your Project you will get this library from sample
attached here.
2.Obtain an AppID (for testing purposes, use the PayPal Sandbox AppID).
Test id is APP-80W284485P519543T
3.Specify the PayPal environment you're addressing (for
example, ENV_SANDBOX or ENV_LIVE) and the business' PayPal Account
as the receiver.
4.Calculate the price of the item(s) or service to be purchased and input that
value into your MPL call.
5.Set the Payment Type (for example, PAYMENT_TYPE_SERVICE or
PAYMENT_TYPE_PERSONAL).
6. Make the MPL payment call.
When you make the call, the customer is presented with an in-app
PayPal log in screen and the payment processing is completed within your app
(there is no browser or webview involved).
7.When the payment flow is complete, MPL returns control to your app.
3. “iOS and Android Mobile application Development Company in India” www.letsnurture.com
Step 1:
Add the necessary PayPal header files to your project. Declare both
INTERNET and READ_PHONE_STATE permissions in the activity declared
in your app's manifest file, like this:
add this permission and activity into menifest file of your project.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<activity
android:name="com.paypal.android.MEP.PayPalActivity"
android:configChanges="keyboardHidden|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
Step 2:
To add the library .jar file to an eclipse project that you can find it from project
attached here .
Step 3:
Initialize the library with the initWithAppID method. The following code sets
the required values needed to initialize the library, as well as setting some
optional values. Note that the environment is set to ENV_SANDBOX (the
PayPal Sandbox) and the static Sandbox AppID is hard-coded into the call. You
can also set the environment to ENV_LIVE or ENV_NONE.
When you make app live chane Enviroment to ENV_LIVE and supply live
app-id.
4. “iOS and Android Mobile application Development Company in India” www.letsnurture.com
// change it with live app id
ppObj = PayPal.getInstance();
if (ppObj == null) {
ppObj = PayPal.initWithAppID(MainActivity.this.getBaseContext(),
"APP-80W284485P519543T", PayPal.ENV_SANDBOX);
}
// true = transaction requires shipping
ppObj.setShippingEnabled(true);
here if we want to use feature of shipping the we just enable
setShippingEnabled(true);
Step 4: Create the payment.
Clicking the PayPal button initiates the checkout call, which can include
different payment parameters and optional criteria for shipping, tax, languages,
and type of payments.
// Create a basic PayPal payment
PayPalPayment newPayment = new PayPalPayment();
char val[] = { '5', '0' };
BigDecimal obj_0 = new BigDecimal("50");
// Set the payment amount, excluding tax and shipping costs
newPayment.setSubtotal(new BigDecimal("50"));
// Set the currency type
newPayment.setCurrencyType("USD");
// Set the recipient for the payment (can be a phone number)
newPayment.setRecipient("rahul@letsnurture.com");
5. “iOS and Android Mobile application Development Company in India” www.letsnurture.com
// newPayment.setMerchantName("Company Name");
Intent paypalIntent = ppObj.checkout(newPayment,
MainActivity.this);
MainActivity.this.startActivityForResult(paypalIntent, 1);
Step 5:
Add a delegate to handle the response returned by the library.
The handler will call one of three types (paymentSucceeded, paymentCanceled,
paymentFailed) based on the result. Here's an example callback:
@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);
if (payKey != null) {
Toast.makeText(getApplicationContext(),"Successfullly Buy an item.", Toast.LENGTH_LONG).show();
}
// // Tell the user their payment succeeded
Log.e("Result success", "Result success-true //" + payKey);
break;
case Activity.RESULT_CANCELED:
// The payment was canceled Tell the user their payment was canceled
Log.e("Result cancled", "Result cancled-true");
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);
6. “iOS and Android Mobile application Development Company in India” www.letsnurture.com
Log.e("Result failed", "Result failed-true");
Toast.makeText(getApplicationContext(), errorMessage,
Toast.LENGTH_LONG).show();
// Tell the user their payment was failed.
break;
}
}