Я использую: Ruby 2.4, Rails 5.2.1, Paypal в режиме песочницы:
gem 'paypal-sdk-rest', '~> 1.7.3'
PayPal платеж как:
items << {
:name => title,
:price => unit_price,
:currency => "USD",
:quantity => quantity,
:description => short_description
}
amount = {
:total => subtotal,
:currency => "USD",
:details => {"subtotal": subtotal, "shipping": "0", "tax": "0"}
}
invoice_number = "invoice-#{rand(1111..9999)}"
@payment = Payment.new({
:intent => "sale",
:payer => {
:payment_method => "paypal"},
:redirect_urls => {
:return_url => "http://localhost:3000/payments/#{order.id}/make_payment",
:cancel_url => "http://localhost:3000/"},
:transactions => [{
:item_list => {
:items => items,
},
:amount => amount,
:description => "Transaction description.",
:invoice_number => invoice_number
}]
})
Оплата создается как:
if @payment.create
render json: {success: true, paymentID: @payment.id}
else
@payment.error # Error Hash
render json: {success: false}
end
Взятие платежа:
if payment.execute(payer_id: params[:payerID])
render json: {msg: 'payment_completed', result: 'completed', }
else
render json: {msg: payment.error, result: 'failed'}
end