Server-Side Implementation
Click here to view the server-side implementation using GraphQL.
Creating transactions
PaymentMethodNonce parameter in the Transaction: Sale call on your server.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.
- .Net
public void canUpdatePaymentResource()
{
Result<PaymentMethodNonce> result = gateway.PayPalPaymentResource.Update(new PayPalPaymentResourceRequest()
{
Amount = 55,
AmountBreakdown = new AmountBreakdownRequest
{
Discount = 15,
Handling = 0,
Insurance = 5,
ItemTotal = 45,
Shipping = 10,
ShippingDiscount = 0,
TaxTotal = 10,
},
CurrencyIsoCode = "USD",
CustomField = "0437",
Description = "My Plan Description",
LineItems = new TransactionLineItemRequest[]
{
new TransactionLineItemRequest
{
Description = "Shoes",
ImageUrl = "https://example.com/products/23434/pic.png",
LineItemKind = TransactionLineItemKind.DEBIT,
Name = "Name #1",
ProductCode = "23434",
Quantity = 1,
TotalAmount = 45,
UnitAmount = 45,
UnitTaxAmount = 10,
Url = "https://example.com/products/23434",
},
},
OrderId = "order-123456789",
PayeeEmail = "bt_buyer_us@paypal.com",
PaymentMethodNonce = nonce,
Shipping = new AddressRequest
{
FirstName = "John",
LastName = "Doe",
StreetAddress = "123 Division Street",
ExtendedAddress = "Apt. #1",
Locality = "Chicago",
Region = "IL",
PostalCode = "60618",
CountryName = "United States of America",
CountryCodeAlpha2 = "US",
CountryCodeAlpha3 = "USA",
CountryCodeNumeric = "484",
InternationalPhone = new InternationalPhoneRequest
{
CountryCode = "1",
NationalNumber = "4081111111",
},
},
ShippingOptions = new ShippingOptionRequest[]
{
new ShippingOptionRequest
{
Amount = 10,
Id = "option1",
Label = "fast",
Selected = true,
Type = "SHIPPING",
},
}
});
Assert.IsTrue(result.IsSuccess());
Assert.IsNotNull(result.Target.Nonce);
}Using device data
Below includes an example call with relevant PayPal parameters and device data:
- c#
TransactionRequest request = new TransactionRequest
{
Amount = 1000.0M,
PaymentMethodNonce = Request.Form["payment_method_nonce"],
DeviceData = Request.Form["device_data"],
OrderId = "Mapped to PayPal Invoice Number",
Options = new TransactionOptionsRequest
{
SubmitForSettlement = true,
PayPal = new TransactionOptionsPayPalRequest
{
CustomField = "PayPal custom field",
Description = "Description for PayPal email receipt"
},
}
};
Result<Transaction> result = gateway.Transaction.Sale(request);
if (result.IsSuccess())
{
System.Console.WriteLine("Transaction ID: " + result.Target.Id);
}
else
{
System.Console.WriteLine(result.Message);
}See the recurring transactions section below for more information on recurring transactions.
Options-StoreInVaultOnSuccess option. If a CustomerId is not included, a new customer will be created. If you want to include a PayPal Billing Agreement with the vaulted payment method, use the Checkout with Vault flow.Currency support
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.
Shipping addresses
Transaction: Sale call. The following fields are required when passing a shipping address for PayPal transactions:Shipping-FirstNameShipping-LastNameShipping-StreetAddressShipping-LocalityShipping-PostalCodeShipping-RegionShipping-CountryCodeAlpha2
For details on how to add a shipping address when creating a transaction, see the transaction reference full example . PayPal validates the shipping address, so it must follow the PayPal address conventions.
BillingAddressId and ShippingAddressId parameters.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:
- c#
Transaction transaction = gateway.Transaction.Find("the_transaction_id");
transaction.PayPalDetails.SellerProtectionStatus;
// "ELIGIBLE"Settlement
Unlike most payment types that settle in batches, we capture PayPal funds immediately when you submit each transaction for settlement.
Capturing greater than authorization amount
You can't settle more than the authorized amount unless your industry and processor support settlement adjustment (settling a certain percentage over the authorized amount); contact us for details. If your capture amount exceeds the allowable limit you will receive the respective settlement response code.
Capturing multiple partial amounts against the same authorization
Transaction: Submit For Partial Settlement.Recurring transactions
TransactionSource parameter with a value of recurring if the customer is not present when you create a PayPal transaction from their Vault record. Typical examples are a recurring subscription or an automatic top-up charge.- c#
TransactionRequest request = new TransactionRequest
{
Amount = 1000.00,
PaymentMethodToken = "the_token",
TransactionSource = "recurring",
Options: TransactionOptionsRequest
{
SubmitForSettlement = true
}
};
Result<Transaction> result = gateway.Transaction.Sale(request);