The sample app

This section describes the sample app, PayPalHereSampleApp, included with the PayPal Here Android SDK.

Functionality of PayPalHereSampleApp

The following tables identify the parts of the that performs each step of the workflow that is described in Working with the SDK.

Following are the parts of the sample app performing each step of the workflow described in Working with the SDK and Basic PayPal transaction workflow.

Setup steps

Workflow step PayPalHereSampleApp code
Initialize the SDK PayPalHereSDK.init() call in LogInActivity.onCreate()
Authenticate the merchant N/A
Set the active merchant setCredentials() call in OAuthLoginActivity.setMerchantAndCheckin
Start monitoring the card reader N/A

Steps in the basic workflow

Workflow step PayPalHereSampleApp code
Start an itemized transaction (invoice) ItemizedActivity.initInvoice() MainActivity.java
Add items to the invoice ItemizedActivity.addFruit()
Finalize a payment CreditCardPeripheralActivity.finalizePayment() (a private method that calls the TransactionManager finalizePayment method)
Finalize a payment with a customer signature N/A
Send a receipt CreditCardPeripheralActivity.java

Variations on the basic workflow

Workflow step PayPalHereSampleApp code
A fixed-amount OnClickListener.onclick() in FixedPriceActivity.java
Card not present transaction CreditCardManualActivity.takePayment()
Authorization and Capture Authorize: mTransactionManager.authorizePayment(…) in SwipeTransactionActivity.java Capture: PayPalHereSDK.getTransactionManager().capturePayment() in AuthorizationCompleteActivity.java

Additional capabilities

Workflow step PayPalHereSampleApp code
Refund a payment CreditCardPeripheralActivity.doRefund() SalesActivity.performRefund()

Notes on the sample app

This section contains notes on the sample app.

Authentication

The mid-tier server provides the ticket ID and merchant information (such as username, business name, and address) to the sample app.

After the sample app has retrieved the access token, the app creates a Credentials object and sends it to a PayPalHereSDK object. This prepares your app MerchantManager object to accept payments. See the OAuthLoginActivity.setMerchantAndCheckIn() method in the sample app OAuthLoginActivity.java file.

The setup process

The sample app work with the test server, which is an instance of the sample server hosted by PayPal. You do not need to set up and run the sample server to run the sample app.

The first time you run a sample app, you are prompted to log into the test server. Type the username teashop and the password 11111111 (eight numeral 1’s). The server gives the ticket ID and merchant information (such as username, business name, and address) to the sample app.

After log in, you are redirected to the PayPal log-in page, where you must log in with a PayPal merchant account username and password. This links the teashop PayPal account to the sample app ID.

After the PayPal account is linked to the app ID, you are taken to the return URL in the test server. The test server completes authentication and then redirects you to the sample app. This enables the sample app call to the PayPal Here API directly through the SDK.

Running the sample app

You can step through the code in one of the sample app while you accept a test payment.

To use a sample app to accept a credit card, you must run the app on a physical device (rather than a simulator), and you must attach a PayPal card reader to the device.

The first time you run the sample app you must log in to the test server with merchant username teashop and password 11111111 (eight number 1’s). After log in, you are taken to the PayPal log in page, where you must log in with a PayPal merchant account username and password. Once you log in to PayPal the sample app completes its setup as described in The setup process above.