PayPal Order

Server-side Implementationanchor

Create payment methodanchor

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 methodanchor

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. Ruby
result = gateway.customer.create(
  :first_name => "Charity",
  :last_name => "Smith",
  :payment_method_nonce => nonce_from_the_client
)
if result.success?
  puts result.customer.id
  puts result.customer.payment_methods[0].token
else
  p result.errors
end

Update an existing customer with a payment methodanchor

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. Ruby
result = gateway.customer.update(
  "a_customer_id", # id of customer to update
  :payment_method_nonce => nonce_from_the_client
)
if result.success?
  puts "customer successfully updated"
else
  p result.errors
end

If the customer can't be found, it will raise a Braintree::NotFoundError.

Alternatively, you can use Payment Method: Create to accomplish the same thing as above.

Process transactionsanchor

Use the transaction API to process customer payments against the PayPal Order:

Currency supportanchor

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 Protectionanchor

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

transaction.paypal_details.seller_protection_status
# => "ELIGIBLE"

Void an orderanchor

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.

See also


Next Page: Additional Options