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. Callbacks
  2. Promises
gateway.customer.create({
  firstName: "Charity",
  lastName: "Smith",
  paymentMethodNonce: nonceFromTheClient
}, (err, result) => {
  result.success;
  // true

  result.customer.id;
  // e.g 160923

  result.customer.paymentMethods[0].token;
  // e.g f28wm
});

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. Callbacks
  2. Promises
gateway.customer.update("theCustomerId", {
  paymentMethodNonce: nonceFromTheClient
}, (err, result) => {
  result.success;
  // true
});
If the customer can't be found, it will return a notFoundError. Alternatively, you can use Payment Method: Create to accomplish the same thing as above.

Updating PayPal Payment Resource After Buyer ApprovalAnchorIcon

In certain edge cases, merchants may need to update some transaction parameters, such as the total amount, after the buyer has approved the payment in the PayPal checkout window. In such cases, it is essential to include updated line items in the server-side call to ensure the final amount reflects the correct total.

These updates can include modifications to line items, currency, custom fields, or any other supported parameter.
To complete an update, use the PayPalPaymentResource.update() method on the server side after tokenization of the payment resource and before calling Customer.create() to vault the payment method.

  1. node
describe("PayPalPaymentResourceGateway", function () {
  describe("update", function () {
    it("can update a payment resource", function (done) {
      let requestParams = {
        amount: "55.00",
        amountBreakdown: {
          discount: "15.00",
          handling: "0.00",
          insurance: "5.00",
          itemTotal: "45.00",
          shipping: "10.00",
          shippingDiscount: "0.00",
          taxTotal: "10.00",
        },
        currencyIsoCode: "USD",
        customField: "0437",
        description: "This is a test",
        lineItems: [
          {
            description: "Shoes",
            imageUrl: "https://example.com/products/23434/pic.png",
            kind: TransactionLineItem.Kind.Debit,
            name: "Name #1",
            productCode: "23434",
            quantity: "1",
            totalAmount: "45.00",
            unitAmount: "45.00",
            unitTaxAmount: "10.00",
            url: "https://example.com/products/23434",
          },
        ],
        orderId: "order-123456789",
        payeeEmail: "[email protected]",
        paymentMethodNonce: Nonces.PayPalOneTimePayment,
        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",
          },
        },
        shippingOptions: [
          {
            amount: "10.00",
            id: "option1",
            label: "fast",
            selected: true,
            type: "SHIPPING",
          },
        ],
      };

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. Callbacks
  2. Promises
gateway.transaction.find("theTransactionId", (err, transaction) => {
  transaction.paypalAccount.sellerProtectionStatus;
  // "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.