Set up PayPal payments
DOCS
Last updated: Aug 15th, 6:03am
Complete the steps to check out using PayPal.
Know before you code
The PayPal authorization flow includes PayPal One Touch, which buyers use to trigger an app switch that brings up the PayPal login and authorization webview, then reverts back to the app to complete the purchase.
Step 1: Display a PayPal button during checkout
Contact your account manager or a PayPal solutions engineer to get a list of approved PayPal Button assets to render the PayPal button.
Step 2: Check out with PayPal
- Implement the
CheckoutListenerinterface on your app's Activity class. - Implement
onResumeoverride to handle the PayPal checkout web re-direct back into your native app. - Use the
CheckoutClientto callpayWithPayPalwith a valid PayPalorderIDand theCheckoutListeneractivity. - Inspect the checkout result in the
onCheckoutCompletecallback to handle checkout errors or to complete the transaction.
1public class MyActivity extends Activity implements CheckoutListener {2 ...34 protected void onResume() {5 super.onResume();6 checkoutClient.onResume(this);7 }89 private void initiatePayPalCheckout() {10 // re-directs to browser11 checkoutClient.payWithPayPal(orderId, this);12 }1314 public void onCheckoutComplete(Exception error, CheckoutResult result) {15 if (error == null) {16 // handle checkout error17 } else if (result instanceof PayPalCheckoutResult) {18 String orderId = result.getOrderId();1920 if (orderId != null) {21 // Send orderID to your server to process the payment22 // Capture or authorize the orderID23 }24 }25 }26}
Calling payWithPayPal redirects your buyer to a Web Browser or Chrome Custom Tab depending on the Android API level. This allows a user to log in with their PayPal account to complete the checkout.