iOS/Android SDK
SDKDeprecated
Important: PayPal Here is deprecated. PayPal doesn't accept new integrations but continues to support existing integrations.
Work with the SDK
To prepare to process transactions with the SDK for the first time, an app must complete these setup operations:
- Initialize the SDK each time the app starts.
- Initialize the merchant by passing their credentials into the SDK.
- Find and Connect to a card reader (for card-present transactions).
After setup is complete, an app must complete these steps to process a basic card-present transaction:
- Create an invoice.
- Add items to the invoice.
- Take a payment using a credit card reader.
- Capture the customer's signature, if required for the transaction.
- Send a receipt.
Note: The SDK provides the UI to capture the signature and display the receipt options.
Note: These are samples only. You should review the sample apps to see how they are used in an actual application.
Initialize the SDK, merchant, and device
- Initialize the SDK.
- iOS (Swift)
- iOS (Obj-C)
- Android
- Windows
1PayPalRetailSDK.initializeSDK()
Initialize the merchant. You pass an
SdkCredential
object, which includes the access token, refresh URL, and the environment. For details, see Token Management.Note: For iOS,
initializeMerchant
also initializes the SDK if it is not already initialized. For iOS, you can callinitializeMerchant
directly without callinginitializeSDK
.
- iOS (Swift)
- iOS (Obj-C)
- Android
- Windows
1let sdkCreds = SdkCredential.init(accessToken: "access token of merchant", refreshUrl: "refresh URL to use to refresh access token after expiry", environment: "either live or sandbox")2PayPalRetailSDK.initializeMerchant(withCredentials: sdkCreds) { (error, merchant) in3 // Code to handle success or failure4 // To continue, this must succeed5}
Device discovery. After you initialize the SDK and merchant, connect to a card reader. The following code demonstrates how to connect:
- You can look for the last known reader.
- You can search for a reader.
- You can auto-connect to the last known reader.
Note: When you use the auto connect method, no SDK UI appears to select a reader because it tries to connect in the background. If you cannot connect to the last known reader, you must use one of the other methods.
- iOS (Swift)
- iOS (Obj-C)
- Android
- Windows
1// previous declaration of deviceManager2let deviceManager = PayPalRetailSDK.deviceManager()3// code to connect to last known reader or find another4deviceManager.connect(toLastActiveReader: { (error, paymentDevice) -> Void in5 // Code to handle success or failure6 // On error, check the error and retry7 // On success for a Bluetooth reader, check for software update8})9// code to search and connect10deviceManager.searchAndConnect({ (error, paymentDevice) -> Void in11 // Code to handle success or failure12 // On error, check the error and retry13 // On success for a Bluetooth reader, check for software update14})15// code to auto-connect to the last known reader16let lastActiveReader = deviceManager?.getLastActiveBluetoothReader()17deviceManager.scanAndAutoConnect(toBluetoothReader: lastActiveReader, callback: { (error, paymentDevice) in18 // Code to handle success or failure19 // On error, check error and connect by another method20 // On success for a Bluetooth reader, check for software update21})
- Reader firmware update. If the connected card reader is a Bluetooth reader, you must check for and start the firmware update.
- iOS (Swift)
- iOS (Obj-C)
- Android
1reader.pendingUpdate.offer({ (error, updateComplete) in2 // Code to handle success or failure3 // On error, check the error and retry4 // On success, continue with the payment flow5})
SDK capabilities
Payment
- Create an invoice. Be sure to provide a unique invoice number to protect against duplicate transactions.
- iOS (Swift)
- iOS (Obj-C)
- Android
- Windows
1var invoice: PPRetailInvoice?2invoice = PPRetailInvoice.init(currencyCode: "USD")3invoice.addItem("My Order", quantity: 1, unitPrice: 1.00, itemId: 123, detailId: nil)4invoice.number = "unique_invoice_number"
- Create a
TransactionContext
using the previously created invoice.
- iOS (Swift)
- iOS (Obj-C)
- Android
- Windows
1var tc: PPRetailTransactionContext?2PayPalRetailSDK.transactionManager().createTransaction(invoice, callback: { (error, context) in3 // On error, handle error. Else, set transaction context to call beginPayment in next step4 self.tc = context5})
- Accept a transaction. This part activates the reader so that the customer can select their payment method and then also adds the listeners that will fire when the payment method is chosen.
- iOS (Swift)
- iOS (Obj-C)
- Android
- Windows
1// Listener called once the transaction is completed2tc.setCompletedHandler { (error, txnRecord) -> Void in3 // if error, handle accordingly, else pop back to view controller and handle success4 self.navigationController?.popToViewController(self, animated: false)5 // txnRecord would have any info needed to record the successful transaction6}7// Setting up the options for the transaction.8let options = PPRetailTransactionBeginOptions()9options.showPromptInCardReader = true10options.showPromptInApp = true11options.preferredFormFactors = []12options.tippingOnReaderEnabled = false13options.amountBasedTipping = false14options.isAuthCapture = false15options.quickChipEnabled = false16// Activates the reader to show the payment options17tc.beginPayment(options)
Payment option | Type | Description |
---|---|---|
showPromptInCardReader | Bool | Prompts the customer to tap/insert/swipe the card and whether that appears on the reader. |
showPromptInApp | Bool | Prompts the customer to tap/insert/swipe the card and whether that UI shows in the integrating app. |
preferredFormFactors | Array | Restricts accepted payment methods (contactless, swipe, chip). |
tippingOnReaderEnabled | Bool | Defines whether the customer is prompted for a tip on the card reader. |
amountBasedTipping | Bool | Defines whether the tipping is amount based or percentage based. |
isAuthCapture | Bool | Defines whether the transaction runs as an authorization or a sale. If true , you also must implement the Receipts API. |
quickChipEnabled | Bool | Enables quick chip processing so customers don't have to leave their card inserted the whole time the transaction is processing. |
Offline payment
This feature is currently only available to US merchants.
Important: To use offline payments, you must enable it on your PayPal account. To enable it, send your account email address and a business case to use offline payments to pph-sdk@paypal.com.
Offline mode is only available with EMV-capable card readers. Also, offline mode forces the supported card readers to only accept swipe transactions.
To use the offline payments feature, your app must check for Internet connectivity. If you have no connectivity, your app must request that the PayPal Here SDK store the transaction as offline on the mobile device. When the Internet connectivity is regained, your app must request that PayPal Here SDK process the pending offline transaction.
You are subject to the following limits on activity with the offline payments feature:
- You can only process transactions under USD $5,000.
- You can only process a total of USD $50,000.
- You must reconnect to the Internet within 24 hours or the offline transactions expire.
These limits are subject to change at PayPal's sole discretion. PayPal informs you of changes by email.
As a partner, your end-user merchants assume all liability for any offline transactions, including those that are subsequently declined, expired, or disputed. Your end-user merchants cannot dispute declined offline transactions. Your end-user merchants also assume all liability for offline transactions if the device is lost, stolen, damaged, or you delete your app before re-connecting to the Internet. Any refunds are processed in the normal course after your end user merchants are re-connected to the Internet.
Before you enable the offline payments feature, you agree to communicate these terms and conditions to your end users and secure their agreement to those terms and conditions before your end users can use the feature.
- Merchant initialization If you have an Internet connection and can call
initializeMerchant
successfully, you can proceed to step 2 to enable offline mode. You do not need to callinitializeMerchantOffline
if you've already completed a successful online merchant initialization. However, if you do not have an Internet connection to callinitializeMerchant
, you can callintializeMerchantOffline
to successfully initialize the merchant before processing offline transactions.
Notes:
Call
initializeMerchantOffline
only if you cannot initially callinitializeMerchant
.You can complete an offline merchant initialization only after successfully completing at least one online merchant initialization on the device.
If you cannot initially call
initializeMerchant
and instead calledinitializeMerchantOffline
, you must callinitializeMerchant
before replaying offline transactions. Before you can process online transactions, online merchant initialization must succeed.
- iOS (Swift)
- iOS (Obj-C)
- Android
1PayPalRetailSDK.initializeMerchantOffline { (error, merchant) in2 // Code to handle success or failure3}
- Enable offline payments to accept payments when you have no internet connection. This will start the offline processing of transactions and save them on the device.
- iOS (Swift)
- iOS (Obj-C)
- Android
1PayPalRetailSDK.transactionManager().startOfflinePayment(callback: { (error, offlinePaymentInfo) in2 // Code to handle success or failure3})
Create a
TransactionContext
using the previously created invoice in the same way as one would for a normal payment.Accept a transaction in the same way as a normal payment. For offline payments the reader will only accept swipe transactions at this time. Transaction options are not available when processing offline payments and also there is a separate completed handler for offline payments.
- iOS (Swift)
- iOS (Obj-C)
- Android
1tc.setOfflineTransactionAdditionHandler({ (error, txnRecord) in2 // if error, handle accordingly, else pop back to view controller and handle success3 self.navigationController?.popToViewController(self, animated: false)4 // txnRecord would have any info needed to record the successful offline saved transaction5})
- Check the status of the offline payment saved on the device.
- iOS (Swift)
- iOS (Obj-C)
- Android
1PayPalRetailSDK.transactionManager().getOfflinePaymentStatus(callback: { (error, offlinePaymentInfo) in2 // Code to handle success or failure3})
- Start processing the offline payments.
- iOS (Swift)
- iOS (Obj-C)
- Android
1PayPalRetailSDK.transactionManager().startReplayOfflineTxns(callback: { (error, offlinePaymentInfo) in2 // Code to handle success or failure of the offline replay3})
- Stop processing the offline payments at any time.
- iOS (Swift)
- iOS (Obj-C)
- Android
1PayPalRetailSDK.transactionManager().stopReplayOfflineTxns(callback: { (error, info) in2 // Status of the remaining offline transactions3})
- Disable offline payments.
Note: The SDK is brought back into online mode once
startReplayOfflineTxns
is called. When this happens, the app does not need to callstopOfflinePayment
to return to online mode.
- iOS (Swift)
- iOS (Obj-C)
- Android
1PayPalRetailSDK.transactionManager().stopOfflinePayment({ (error, info) in2 // Status of the remaining offline transactions3})
Refund
Refunds can either be done within your app or you can use our Refund API to incorporate refund functionality in your back-office. These steps outline how to complete a refund within your app:
- Create a
TransactionContext
for the invoice you would like to refund. ThecreateRefundTransaction
method takes in the following parameters:PayPal invoice ID
,transaction ID
,payment method
of the transaction, and acallback handler
.
- iOS (Swift)
- iOS (Obj-C)
- Android
- Windows
1PayPalRetailSDK.transactionManager().createRefundTransaction(paypalInvoiceId, transactionNumber: transactionNumber, paymentMethod: paymentMethod, callback: refundHandler)
The callback handler accepts an error object and transaction context. If the error object is not nil, then handle accordingly. Otherwise, use the transaction context to call beginRefund
.
- Call into
beginRefund
to determine whether the card is present for the refund, and to process the refund. This code would be used as part of the callbacks mentioned in thecreateRefundTransaction
method.
- iOS (Swift)
- iOS (Obj-C)
- Android
- Windows
1// Listener that gets called once the refund processes2tc.setCompletedHandler { (error, txnRecord) -> Void in3 // if error, handle accordingly, else pop back to view controller and handle success4 self.navigationController?.popToViewController(self, animated: false)5 // txnRecord would have any info needed to record the successful refund6}7// Begins refund process and asks if a card is present for the refund8tc.beginRefund(true, amount: refundAmount)
Additional capabilities
The SDK also supports several additional capabilities:
- Adding a referrer code to a transaction
- Accepting keyed-in card payments
- Adding a unique invoice ID to a transaction
When your integration is complete, check the going live page to ensure that you have everything ready for activation. Once that is working, you can implement other customizations that are available with the SDK into your integration.