Проблема сопоставления сумм с PaypalExpressGateway.setup_authorization - PullRequest
0 голосов
/ 28 марта 2019

Я использую клиент ruby ​​с activemerchant для создания вызова API песочницы Paypal.Скрипт вызывается из командной строки, поэтому переменные заполняются параметрами командной строки.Вот пример кода:

login = ARGV[0]
password = ARGV[1]
signature = ARGV[2]
ip = ARGV[3]
subtotal = ARGV[4]
shipping = ARGV[5]
handling = ARGV[6]
tax = ARGV[7]
currency = ARGV[8]
return_url = ARGV[9]
cancel_return_url = ARGV[10]
allow_guest_checkout = ARGV[11]
items = JSON.parse(ARGV[12])

ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
    login: login,
    password: password,
    signature: signature
}

gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)

setup_hash = {
    ip: ip, 
    items: items, 
    subtotal: Integer(subtotal),
    shipping: Integer(shipping),
    handling: Integer(handling), 
    tax: Integer(tax), 
    currency: currency, 
    return_url: return_url, 
    cancel_return_url: cancel_return_url, 
    allow_guest_checkout: allow_guest_checkout
}

amount = subtotal.to_i + shipping.to_i + handling.to_i + tax.to_i
puts "amount: " + amount.to_s
puts "items: " + items.to_s
response = gateway.setup_authorization(amount, setup_hash)
if !(response.success?)
    puts response.message.to_s
end

А вот что я получаю в консоли:

amount: 10000
items: [{"name"=>"sample", "description"=>"desc", "quantity"=>1, "amount"=>10000}]
The totals of the cart item amounts do not match order amounts.

Итак, как получается, что 10000 по количеству не соответствует 10000 по предметам?

1 Ответ

0 голосов
/ 18 апреля 2019

После долгой и скучной отладки я обнаружил следующее: внутренний хеш items должен быть [:{name=>"sample", :description=>"desc", :quantity=>1, :amount=>10000}] вместо [{"name"=>"sample", "description"=>"desc", "quantity"=>1, "amount"=>10000}] в примере выше.

Итак, я изменил JSON-анализатор на nice_hash и items = ARGV[12].json работает как шарм.

...