Instant Payment - nov/paypal-express GitHub Wiki
Call SetExpressCheckout using this code and let user redirect to the given redirect URI.
paypal_options = {
no_shipping: true, # if you want to disable shipping information
allow_note: false, # if you want to disable notes
pay_on_paypal: true # if you don't plan on showing your own confirmation step
}
request = Paypal::Express::Request.new(
:username => SET_YOUR_OWN,
:password => SET_YOUR_OWN,
:signature => SET_YOUR_OWN
)
payment_request = Paypal::Payment::Request.new(
:currency_code => :JPY, # if nil, PayPal use USD as default
:description => FOO, # item description
:quantity => 1, # item quantity
:amount => 1.00, # item value
:custom_fields => {
CARTBORDERCOLOR: "C00000",
LOGOIMG: "https://example.com/logo.png"
}
)
response = request.setup(
payment_request,
YOUR_SUCCESS_CALLBACK_URL,
YOUR_CANCEL_CALLBACK_URL,
paypal_options # Optional
)
response.redirect_uriAssume the end-user approved the payment request on PayPal.com and redirect back to your site.
In the redirect back request, you get token and PayerID in query string.
Remember that if you are in development and you want to use a sandbox account, you must enable sandbox mode in development.rb
Paypal.sandbox!if you specified pay_on_paypal: true in the first step, you can skip this bit and move straight to completing the transaction, below.
If you didn't specify pay_on_paypal: true in the first step, it falls on you to show a confirmation step to the user.
Call GetExpressCheckoutDetails using this code to get the details to show in that confirmation step.
response = request.details(token)
# inspect these attributes for more details
response.payer
response.amount
response.ship_to
response.payment_responsesWhether or not you specified pay_on_paypal: true, you need to confirm the payment when your success callback URL is called.
Call DoExpressCheckoutPayment using this code.
response = request.checkout!(
token,
payer_id,
payment_request
)
# inspect this attribute for more details
response.payment_info