Server-side Implementation

Create payment methodAnchorIcon

Once the customer has successfully authenticated with PayPal, you can use one of the following calls to create a payment method. You will be using this payment method for processing transactions against the PayPal Order.

Create a new customer with a payment methodAnchorIcon

If you do not already have a record for this customer in your Vault, you can create a new customer with a payment method using Customer: Create with the paymentMethodNonce() parameter.
  1. Java
CustomerRequest request = new CustomerRequest()
    .firstName("Fred")
    .lastName("Jones")
    .paymentMethodNonce(nonceFromTheClient);

Result<customer> result = gateway.customer().create(request);
result.isSuccess(); // true
Customer customer = result.getTarget();
customer.getId(); // e.g. 160923
customer.getPaymentMethods().get(0).getToken(); // e.g. f28w

Update an existing customer with a payment methodAnchorIcon

If the customer already exists in your Vault, you can add a new payment method to that customer using Customer: Update with the paymentMethodNonce() parameter.
  1. Java
CustomerRequest request = new CustomerRequest()
    .paymentMethodNonce(nonceFromTheClient);

Result<customer> updateResult = gateway.customer().update("the_customer_id", request);
updateResult.isSuccess(); // true
If the customer can't be found, it will throw a NotFoundException. Alternatively, you can use Payment Method: Create to accomplish the same thing as above.

Process transactionsAnchorIcon

Use the transaction API to process customer payments against the PayPal Order:

Currency supportAnchorIcon

The customer will be charged in the currency associated with the merchantAccountId passed in the Transaction: Sale call. We support all currencies that PayPal REST APIs support. For details on accepting foreign currencies with PayPal, see our PayPal account setup guide.

Seller ProtectionAnchorIcon

By passing a shipping address, you may also be eligible for PayPal Seller Protection. You can check the status of Seller Protection as follows:
  1. Java
Transaction transaction = gateway.transaction().find("the_transaction_id");
transaction.getPayPalDetails().getSellerProtectionStatus(); // "ELIGIBLE"

Void an orderAnchorIcon

As the PayPal Order is represented by a customer's payment method, to void an order you need to delete the payment method by calling Payment Method: Delete.

Update payment method nonceAnchorIcon

After a payment method nonce is generated by the Client SDK, merchants can still modify certain parameters of the underlying AS2 object using the PayPalPaymentResource.update method. Upon a successful update, a new nonce will be returned, and the original nonce passed into the request will be consumed.

  1. Java
TransactionLineItemRequest lineItem = new TransactionLineItemRequest().
            description("Shoes").
            imageUrl("https://example.com/products/23434/pic.png").
            kind(TransactionLineItem.Kind.DEBIT).
            name("Name #1").
            productCode("23434").
            quantity(new BigDecimal("1")).
            totalAmount(new BigDecimal("45.00")).
            unitAmount(new BigDecimal("45.00")).
            unitTaxAmount(new BigDecimal("10.00")).
            url("https://example.com/products/23434");
 
        PayPalPaymentResourceRequest request = new PayPalPaymentResourceRequest().
            paymentMethodNonce(originalNonce).
            amount(new BigDecimal("55.00")).
            amountBreakdown().
                discount(new BigDecimal("15.00")).
                handling(new BigDecimal("0.00")).
                insurance(new BigDecimal("5.00")).
                itemTotal(new BigDecimal("45.00")).
                shipping(new BigDecimal("10.00")).
                shippingDiscount(new BigDecimal("0.00")).
                taxTotal(new BigDecimal("10.00")).
                done().
            currencyIsoCode("USD").
            customField("0437").
            description("This is a test").
            addLineItem(lineItem).
            orderId("order-123456789").
            payeeEmail("bt_buyer_us@paypal.com").
                       shipping().
                firstName("John").
                lastName("Doe").
                streetAddress("123 Division Street").
                extendedAddress("Apt. #1").
                locality("Chicago").
                region("IL").
                postalCode("60618").
                countryName("United States").
                countryCodeAlpha2("US").
                countryCodeAlpha3("USA").
                countryCodeNumeric("484").
                internationalPhone().
                    countryCode("1").
                    nationalNumber("4081111111").
                    done().
                done().
            shippingOption().
                amount(new BigDecimal("10.00")).
                id("option1").
                label("fast").
                selected(true).
                type("SHIPPING").
                done();
 
 
        Result<PaymentMethodNonce> result = gateway.paypalPaymentResource().update(request);
        result.isSuccess(); // true
 
        CustomerRequest request = new CustomerRequest()
             .firstName("Fred")
             .lastName("Jones")
             .paymentMethodNonce(result.getTarget());