1
votes

I'm having trouble recently with the paypal api for ruby (https://github.com/paypal/merchant-sdk-ruby).

I'm trying to set a checkout with more than one item, with the PaymentDetailsItem, but when I send the request I get an error saying: "The totals of the cart item amounts do not match order amounts."

I've already checked that, as you can see on the code below. My OrderTotal equals the sum of ItemTotal, ShippingTotal, HandlingTotal and TaxTotal.

I've tried so many things, the paypal api have a very bad documentation and I can't find any examples online about this. Thank you very much for your help.

@api = PayPal::SDK::Merchant::API.new
@set_express_checkout = @api.build_set_express_checkout({
:SetExpressCheckoutRequestDetails => {
:ReturnURL => "#{ENV['HOST']}/return",
:CancelURL => "#{ENV['HOST']}/cancel",

:PaymentDetails => [{

  :OrderTotal => {
    :currencyID => currency,
    :value => "10.00" 
  },

  :ItemTotal => {
    :currencyID => currency,
    :value => "10.00" 
  },

  :ShippingTotal => {
    :currencyID => currency,
    # :value => ship 
    :value => "0.00"
  },

  :TaxTotal => {
    :currencyID => currency,
    :value => "0.00" 
  },

  :NotifyURL => "#{ENV['HOST']}/ipn_notify",

  :PaymentDetailsItem => 
  [
    {
      :Name => "Some Product", 
      :Quantity => 1,
      :Amount => {
        :currencyID => "EUR",
        :value => "5.00"
      },
      :ItemCategory => "Physical"
    }
  ],
  :PaymentDetailsItem => 
  [
    {
      :Name => "Other Product",
      :Quantity => 1,
      :Amount => {
        :currencyID => "EUR",
        :value => "5.00" 
      },
      :ItemCategory => "Physical" 
    }
  ], 
  :PaymentAction => "Authorization" }] } })
@set_express_checkout_response = @api.set_express_checkout(@set_express_checkout)
1

1 Answers

-1
votes

Remove one of the :PaymentDetailsItem key and add items as shown below.

:PaymentDetailsItem =>
  [
    {
      :Name => "Some Product",
      :Quantity => 1,
      :Amount => {
        :currencyID => "EUR",
        :value => "5.00"
      },
      :ItemCategory => "Physical"
    },
    {
      :Name => "Other Product",
      :Quantity => 1,
      :Amount => {
        :currencyID => "EUR",
        :value => "5.00"
      },
      :ItemCategory => "Physical"
    }
  ]