Server-Side Implementation
Your integration may be impacted by upcoming certificate changes. Visit our best practices guide to learn more.
Creating transactions
payment_method_nonce
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.
- Ruby
describe Braintree::PayPalPaymentResource do
describe "self.update" do
it "successfully updates a payment resource" do
nonce = nonce_for_paypal_account(
:intent => "order",
:payment_token => "fake-paypal-payment-token",
:payer_id => "fake-paypal-payer-id",
)
result = Braintree::PayPalPaymentResource.update(
:amount => BigDecimal("55.00"),
:amount_breakdown => {
:discount => BigDecimal("15.00"),
:handling => BigDecimal("0.00"),
:insurance => BigDecimal("5.00"),
:item_total => BigDecimal("45.00"),
:shipping => BigDecimal("10.00"),
:shipping_discount => BigDecimal("0.00"),
:tax_total => BigDecimal("10.00"),
},
:currency_iso_code => "USD",
:custom_field => "0437",
:description => "This is a test",
:line_items => [{
:description => "Shoes",
:image_url => "https://example.com/products/23434/pic.png",
:kind => "debit",
:name => "Name #1",
:product_code => "23434",
:quantity => "1",
:total_amount => BigDecimal("45.00"),
:unit_amount => BigDecimal("45.00"),
:unit_tax_amount => BigDecimal("10.00"),
:url => "https://example.com/products/23434",
}],
:order_id => "order-123456789",
:payee_email => "bt_buyer_us@paypal.com",
:payment_method_nonce => nonce,
:shipping => {
:country_name => "United States",
:country_code_alpha2 => "US",
:country_code_alpha3 => "USA",
:country_code_numeric => "484",
:extended_address => "Apt. #1",
:first_name => "John",
:international_phone => {
:country_code => "1",
:national_number => "4081111111",
},
:last_name => "Doe",
:locality => "Chicago",
:postal_code => "60618",
:region => "IL",
:street_address => "123 Division Street",
},
:shipping_options => [{
:amount => BigDecimal("10.00"),
:id => "option1",
:label => "fast",
:selected => true,
:type => "SHIPPING"
}],
)
expect(result.success?).to eq(true)
expect(result.payment_method_nonce).not_to be_nil
expect(result.payment_method_nonce.nonce).not_to be_nil
end
Using device data
Below includes an example call with relevant PayPal parameters and device data:
- Ruby
result = gateway.transaction.sale(
:amount => "10.00",
:payment_method_nonce => params[:payment_method_nonce],
:device_data => params[:device_data],
:order_id => "Mapped to PayPal Invoice Number",
:options => {
:submit_for_settlement => true,
:paypal => {
:custom_field => "PayPal custom field",
:description => "Description for PayPal email receipt",
},
}
)
if result.success?
"Success ID: #{result.transaction.id}"
else
result.message
end
See the recurring transactions section below for more information on recurring transactions.
options-store_in_vault_on_success
option. If a customer_id 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-first_name
shipping-last_name
shipping-street_address
shipping-locality
shipping-postal_code
shipping-region
shipping-country_code_alpha2
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.
billing_address_id
and shipping_address_id
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:
- Ruby
transaction = gateway.transaction.find("the_transaction_id")
transaction.paypal_details.seller_protection_status
# => "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
transaction_source
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.- Ruby
result = gateway.transaction.sale(
:amount => "1000.00",
:payment_method_token => "payment_method_token",
:transaction_source => "recurring",
:options => {
:submit_for_settlement => true,
}
)