Server-side Implementation
Create payment method
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 method
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.
- Callbacks
- 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 method
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.
- Callbacks
- Promises
gateway.customer.update("theCustomerId", {
paymentMethodNonce: nonceFromTheClient
}, (err, result) => {
result.success;
// true
});notFoundError. Alternatively, you can use
Payment Method: Create to accomplish the
same thing as above.
Updating PayPal Payment Resource After Buyer Approval
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.
Note The paymentMethodNonce is a required parameter. The update() call returns a new nonce, which must be used with Customer.create() to ensure the updated payment resource is properly vaulted. In addition to the required parameter, merchants can include any optional fields in the update call based on what needs to be modified. The sample code snippet below includes the full list of supported parameters. You can update only the fields relevant to your specific use case.
- 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 transactions
Use the transaction API to process customer payments against the PayPal Order:
- Create a transaction using payment information
- Submit a transaction for settlement to get paid
- Find a transaction
- Search for transactions that match specific criteria
- Void a transaction to cancel it before it settles
- Refund a settled transaction to return funds to the customer
Currency support
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 Protection
By passing a shipping address, you may also be eligible for
PayPal Seller Protection. You can check the status of Seller Protection as follows:
- Callbacks
- Promises
gateway.transaction.find("theTransactionId", (err, transaction) => {
transaction.paypalAccount.sellerProtectionStatus;
// "ELIGIBLE"
});Void an order
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.