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 payment_method_nonce parameter.
  1. Python
result = gateway.customer.create({
    "first_name": "Charity",
    "last_name": "Smith",
    "payment_method_nonce": nonce_from_the_client
})

result.is_success
# True

result.customer.id
# e.g 160923

result.customer.payment_methods[0].token
# 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 payment_method_nonce parameter.
  1. Python
result = gateway.customer.update("the_customer_id", {
    "payment_method_nonce": nonce_from_the_client
})
result.is_success
# True
If the customer can't be found, it will throw a NotFoundError exception. 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. python
class PayPalPaymentResource(Resource):
    @staticmethod
    def update(request):
        return Configuration.gateway().paypal_payment_resource.update(request)

    @staticmethod
    def update_signature():
        amount_breakdown = [
            "discount",
            "handling",
            "insurance",
            "item_total",
            "shipping",
            "shipping_discount",
            "tax_total"
        ]

        line_item = [
            "commodity_code",
            "description",
            "discount_amount",
            "image_url",
            "kind",
            "name",
            "product_code",
            "quantity",
            "tax_amount",
            "total_amount",
            "unit_amount",
            "unit_of_measure", 
            "unit_tax_amount",
            "upc_code",
            "upc_type",
            "url",
        ]

        shipping_request = [
            "company",
            "country_name",
            "country_code_alpha2",
            "country_code_alpha3",
            "country_code_numeric",
            "extended_address",
            "first_name",
            {
                "international_phone": [
                    "country_code",
                    "national_number"
                ]
            },
            "last_name",
            "locality",
            "postal_code",
            "region",
            "street_address"
        ]

        shipping_option = [
            "amount",
            "id",
            "label",
            "selected",
            "type"
        ]

        signature = [
            {
                "paypal_payment_resource": [
                    "amount",
                    { 
                        "amount_breakdown": amount_breakdown
                    },
                    "currency_iso_code",
                    "custom_field",
                    "description",
                    {
                        "line_items": line_item
                    },
                    "order_id",
                    "payee_email",
                    "payment_method_nonce",
                    {
                        "shipping": shipping_request
                    },
                    {
                        "shipping_options": shipping_option
                    }
                ]
            }
        ]
        return signature

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 merchant_account_id 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. Python
transaction = gateway.transaction.find("the_transaction_id")

transaction.paypal_details.seller_protection_status
# "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.