Additional Optionsanchor

When creating a payment method, you can pass additional options on the server side to manage the transactions processed against the PayPal Order.

  • Amount: Allows you to update the amount of the shopping cart that was approved by the Buyer. Note the currency can't be updated at this step. It has to match the currency passed at the time of tokenizing the payment.
  • Order ID: Use this field to pass additional information about the PayPal Order. When it comes to the Order itself, the Order ID stays on Braintree. However, in the case of the PayPal Order's captures, Order IDs are received by the PayPal API and are recorded under 'invoice number' on PayPal's side. These invoice numbers can be used for lookup in the PayPal Console for captures. PayPal invoice numbers must be unique in your PayPal business account.
  • Custom field: Use this field to pass information directly to PayPal via the API for your own tracking purposes. Customers do not see this value, but you can see it in reports from your PayPal console.
  • Description: Description of the transaction that is displayed to customers in PayPal email receipts. Max 127 characters.
  • Shipping: Shipping destination address input.

Examplesanchor

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,
  :options => {
    :paypal => {
      :amount => "10.00",
      :order_id => "PayPal_Invoice_Number",
      :custom_field => "My_Custom_Field",
      :description => "My_Description",
      :shipping => {
        :firstName => 'Charity',
        :lastName => 'Smith',
        :locality => 'San Jose',
        :postalCode => '95131',
        :streetAddress => '111 Main St',
        :region => 'CA',
        :countryCodeAlpha2 => 'US'
      }
    }
  }
)
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,
  :options => {
    :paypal => {
      :amount => "10.00",
      :order_id => "PayPal_Invoice_Number",
      :custom_field => "My_Custom_Field",
      :description => "My_Description",
      :shipping => {
        :firstName => 'Charity',
        :lastName => 'Smith',
        :locality => 'San Jose',
        :postalCode => '95131',
        :streetAddress => '111 Main St',
        :region => 'CA',
        :countryCodeAlpha2 => 'US'
      }
    }
  }
)
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.


Next Page: Testing and Go Live