Consumer advisory: The PayPal™ payment service is regarded as a stored value facility under Singapore law. As
such, it does not require the approval of the Monetary Authority of Singapore. You are advised to read the terms
and conditions carefully.
Notice of non-liability:
PayPal, Inc. is providing the information in this document to you “AS-IS” with all faults. PayPal, Inc. makes no
warranties of any kind (whether express, implied or statutory) with respect to the information contained herein.
PayPal, Inc. assumes no liability for damages (whether direct or indirect), caused by errors or omissions, or
resulting from the use of this document or the information contained in this document or resulting from the
application or use of the product or service described herein. PayPal, Inc. reserves the right to make changes to
any information herein without further notice.
Creating Preapproval PINs During Preapproval Checkout .................................. 37
Mobile Payments Library Developer Guide and Reference – Android OS Edition July 2011 3
3. Submitting Your Application to PayPal ................................................... 38
A. Currencies Supported by PayPal ............................................................. 39
B. Countries and Regions Supported by PayPal ......................................... 41
4 July 2011 PayPal Mobile Payments Developer Guide and Reference – Android OS Edition
Version
Date Published
Description
1.5.5
July 2011
Initialization is recallable and completes within 3 sec down from 20-30
sec.
„Keep Me Logged‟ in functionality reinstated.
Merchant has the ability cancel transaction from dynamic amount
calculation.
1.5
February 2011
Improved Tablet Support
1.1.1
January 2011
Eliminated “Keep Me Logged In” functionality
Preface
The PayPal Mobile Payments library provides secure, extensible, and scalable PayPal payment
functionality to the Android platform.
Purpose
The PayPal Mobile Payments Library provides an easy way for you to integrate payments into
your Android applications. You can download the library from X.com and include it in your
application. With the library, you need only a few lines of code to integrate the payments library
with your application.
When a buyer makes a payment, the library controls the checkout experience – logging in,
reviewing, and completing the payment. After buyers complete their payments, the library returns
the buyer to your application.
Scope
This document describes how to integrate the PayPal Mobile Payments Library with your
application. You must create and provide your build to PayPal so PayPal can review your
application before it is approved to accept payments via the library. The approval process is
described later in the document.
OS and Hardware Support
The PayPal Mobile Payments Library supports Android OS 1.5 and higher. All Android devices
are supported.
Revision History
The following table lists revisions made to the Mobile Payments Library Developer Guide and
Reference.
Mobile Payments Library Developer Guide and Reference – Android OS Edition July 2011 5
Version
Date Published
Description
1.1
December 2010
Added information about preapproval; dropped support for the
enumeration value BUTTON_118x24
1.0
September 2010
Adaptive Payments Support
0.7
May 2010
First publication
6 July 2011 PayPal Mobile Payments Developer Guide and Reference – Android OS Edition
Where to Go for More Information
Adaptive Payments Developer Guide
Sandbox User Guide
Merchant Setup and Administration Guide
PayPal X Developer Network (x.com)
Mobile Payments Library Developer Guide and Reference – Android OS Edition July 2011 7
1. PayPal Mobile Payments Library
This section provides details about the Mobile Payments Library API, and it provides instructions
and examples for integrating the library with your Android application.
Mobile Payments Library API Reference
The flow of the library is:
1. Your application initializes the library.
2. The library creates a Pay with PayPalButton and returns it to you so you can place it on
the screen.
3. (Optional) Your application enables Dynamic Amount Calculation (see step 4 below) to
recalculate the payment amount, tax, currency, and shipping values when buyers change the
shipping address for the payment.
4. When buyers select the Pay with PayPal button, the library takes them through the PayPal
Checkout experience.
5. (Optional) If you enabled dynamic amount calculation in step 1 above:
a. When a buyer chooses an address for the payment, the library returns a call back to
your application with the address information.
b. Your application recalculates the payment and other amounts, based on the address.
c. The library returns the buyer to the checkout experience, which uses the updated
payment amount, tax, currency, and shipping values.
6. After buyers complete their payments, the library returns a callback to your application with
the status of the payment and the pay key. Note: at this time, the library is still in control of
the UI and has not returned control to your application.
7. After the library flow is complete, an activity result will be posted to be received by your
application.
Declaring the Library and Permissions in AndroidManifest.xml
Since the Mobile Payments Library is an Activity, you must declare it in the
AndroidManifest.xml file of your application. You must also declare Internet and Phone
State permissions that the Library requires. Below is an example AndroidManifest.xml. Sections
specifically relevant to the Library are in bold:
Mobile Payments Library Developer Guide and Reference – Android OS Edition July 2011 9
Parameter
Description
context:
(Required) The context.
appID:
(Required) PayPal Application ID from X.com.
This will be different for each server. Thus, the appID will be
different for Stage and Sandbox. Any appID value can be used when
testing on „none‟ since the library does not contact the server when
set to this.
server:
(Required) Sets the PayPal server to Live, Sandbox, or None.
Allowable values are:
ENV_LIVE – Use the PayPal production servers.
(does not support simulators)
ENV_SANDBOX – Use the PayPal testing servers.
ENV_NONE - Do not use any PayPal servers. Operate in
demonstration mode, instead. Demonstration mode lets you view
various payment flows without requiring production or test accounts
on PayPal servers. Network calls within the library are simulated by
using demonstration data held within the library.
Required Methods in the Mobile Payments Library
initWithAppID Method
The initWithAppID method creates and returns the PayPal object. You must pass in the context
and the unique application ID (appID) that PayPal has provided. You can choose whether to use
the live or sandbox server, or use non-networked (Demo) mode (see below).
static public PayPal initWithAppID(Context context, String appID, int
server)
An example of initializing the Library with this method is:
NOTE: The initWithAppID method should only be invoked once. After initialization,
reference the PayPal object using the getInstance method instead. Calling the
initWithAppID method more than once will throw an IllegalStateException.
NOTE: If you do not set the optional parameter forEnvironment, the library defaults to use
the PayPal production the servers. When testing your application, PayPal recommends that
you initialize the library to use the PayPal test servers, instead.
10 July 2011 PayPal Mobile Payments Developer Guide and Reference – Android OS Edition
NOTE: The Mobile Payments Library binds specific devices to specific application IDs, for
enhanced security. For each of your application IDs, you must use a different sandbox
account for each of your devices. If you try to login with a different account on a device
after binding, you will get the following error: “This app is attached to another PayPal
account. To remove it, the account holder must visit PayPal.com and select Mobile
Applications from the profile.”
To switch a device or simulator to use a different sandbox account, go to the PayPal
Sandbox website on your computer, login with the account that was used on the device,
select Profile > Mobile Applications, and then unbind the device from the application ID.
getCheckoutButton Method
You must get the Pay with PayPal payment button from the Mobile Payments Library. Use this
method, which returns a CheckoutButton (a subclass of LinearLayout), which you can place
in your application.
public CheckoutButton getCheckoutButton(Context context, int style, int
textType);
Example code of getting the Payment button from the Library is:
For images of the different button types, see “Enumerated Values in the
Mobile Payments Library” on page 28.
context:
(Required) The context
textType:
(Required) The type of button to be used. The type will determine the
text that is to be used on the button. This has no bearing on the payment
and only affects the button itself. Allowable values are:
The Library uses the native Android Activity mechanism to start the checkout flow, and to
communicate completion back to you. In addition to the onActivityResult callback, you can
implement PayPalResultDelegate to be informed immediately upon successful completion of
a payment.
To start the PayPal payment, you must start the Library activity, using the Android method
startActivityForResult. Do this when buyers touch the Pay with PayPal button (which
you placed on your page with the getCheckoutButton method)
You must first create the PayPal intent and give it the Payment object. There are two types of
payment objects. PayPalPayment handles simple payments, which support single receivers of
payments with one transaction and a few details. PayPalAdvancedPayment handles parallel
and chained payments, which support multiple receivers of payment with one transaction and
with additional details, such as invoice data.
In the following example, the buyer checks out with a simple payment for a single recipient:
For more information on receivers and how to use them, see “Custom Objects in the Mobile
Payments Library” on page 23.
Note: On older devices and/or firmware, starting the activity may take significant time to
complete, resulting in an “Activity is not responding” popup if the user attempts to enter input
during this time. It is recommended to create a loading thread with an animation of some sort if
you witness this regularly.
Dynamic Amount Calculation
The Mobile Payments Library allows you to modify the payment based on the buyer‟s shipping
address. For instance, you might want to recalculate the tax amount based on the buyer‟s location.
To enable this, use the optional method enableDynamicAmountCalculation() (see
“Optional Methods” below. You must provide the logic that creates the new payment values
based on the buyer‟s address. The library includes a PaymentAdjuster class for this.
To use this feature, one of your classes (not an Activity) must implement “PaymentAdjuster”, as
well as implement “Serializable”. For simplicity, we recommend creating a new class that does
this. This class must include the following methods:
Mobile Payments Library Developer Guide and Reference – Android OS Edition July 2011 13
Parameter
Description
address
The buyer's address that should be used when calculating adjusted tax
and shipping amounts.
currency
The currency of the payment.
amount
The current subtotal amount.
tax
The current tax amount.
shipping
The current shipping amount.
Parameter
Description
address
The buyer's address that should be used when calculating adjusted tax
and shipping amounts.
currency
The currency of the payment.
receivers
A collection of current receivers and the amounts associated with each
receiver.
public MEPAmounts adjustAmount(MEPAddress address, String currency,
String amount, String tax, String shipping);
Your method must return a new MEPAmounts object (see Custom Objects section). This object
contains the new currency and amounts.
public Vector<MEPReceiverAmounts> adjustAmountsAdvanced(MEPAddress
Your method must return a new Vector<MEPReceiverAmounts> to update the library with
adjusted amounts for each receiver. (See Custom Objects section).
Applications may cancel a payment during the PaymentAdjust callback by returning 'null'.
Returning null will cancel the entire payment. A dialog will be presented to the user indicating
that the adjustment failed and the payment is being cancelled. Applications may also call
PayPal.setAdjustPaymentError(String message) to establish the message that will be presented.
Otherwise a standard message will be used. The error message should be established prior to
failing the the payment adjust.
When you create the PayPal Activity, you must pass through the PaymentAdjuster class to
another form of the checkout method. For example, if you created an “AdjustAmounts” class
that implements PaymentAdjuster and contains the adjustAmount method, your code could
be:
AdjustAmounts adjustClass = new AdjustAmounts();
Intent paypalIntent = PayPal.getInstance().checkout([your payment
object], this, adjustClass);
this.startActivityForResult(paypalIntent, 1);
14 July 2011 PayPal Mobile Payments Developer Guide and Reference – Android OS Edition
Method Sequence
The following diagram illustrates the sequence of methods required to implement the checkout
experience.
Mobile Payments Library Developer Guide and Reference – Android OS Edition July 2011 15
Loading...
+ 33 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.