Set up card payments
DOCS
Last updated: Aug 15th, 5:55am
Complete the steps to check out using credit or debit cards. Generate an approved order that is ready when finalizing the card payment. The PayPal SDK processes card payments using the 3D Secure verification flow.
Step 1: Create a payment card
Create a CardBuilder from the customer card information that the user entered in your app.
1class MyActivity extends Activity implements CheckoutListener {2 ...34 private CardBuilder captureCardInformation() {5 return new CardBuilder()6 .cardNumber("4111111111111111")7 .expirationMonth("01")8 .expirationYear("2021")9 .cvv("123");10 }11}
Step 2: Check out with the card
- Implement the
CheckoutListenerinterface on your app's Activity class. - Implement
onResumeoverride to handle any potential 3DS web re-directs back into your native app. - Use the
CheckoutClientto callpayWithCardwith 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 initiateCardCheckout() {10 // re-directs to browser when 3DS challenge occurs11 CardBuilder cardBuilder = captureCardInformation();12 checkoutClient.payWithCard(cardBuilder, orderId, this);13 }1415 public void onCheckoutComplete(Exception error, CheckoutResult result) {16 if (error == null) {17 // handle checkout error18 } else if (result instanceof CardCheckoutResult) {19 String orderId = result.getOrderId();2021 if (orderId != null) {22 // Send orderID to your server to process the payment23 // Capture or authorize the orderID24 }25 }26 }27}