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 ...
    3
    4 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

    1. Implement the CheckoutListener interface on your app's Activity class.
    2. Implement onResume override to handle any potential 3DS web re-directs back into your native app.
    3. Use the CheckoutClient to call payWithCard with a valid PayPal orderID and the CheckoutListener activity.
    4. Inspect the checkout result in the onCheckoutComplete callback to handle checkout errors or to complete the transaction.
      1public class MyActivity extends Activity implements CheckoutListener {
      2 ...
      3
      4 protected void onResume() {
      5 super.onResume();
      6 checkoutClient.onResume(this);
      7 }
      8
      9 private void initiateCardCheckout() {
      10 // re-directs to browser when 3DS challenge occurs
      11 CardBuilder cardBuilder = captureCardInformation();
      12 checkoutClient.payWithCard(cardBuilder, orderId, this);
      13 }
      14
      15 public void onCheckoutComplete(Exception error, CheckoutResult result) {
      16 if (error == null) {
      17 // handle checkout error
      18 } else if (result instanceof CardCheckoutResult) {
      19 String orderId = result.getOrderId();
      20
      21 if (orderId != null) {
      22 // Send orderID to your server to process the payment
      23 // Capture or authorize the orderID
      24 }
      25 }
      26 }
      27}

      Next step

      Process the order