setting tax amount in Active Merchant / PayPal Express Checkout

三世轮回 提交于 2019-12-06 06:23:25

问题


I need to know how to pass a tax amount to PayPal Express Checkout using Active Merchant and rails. Everything is working (completing transations) except I can't figure out for the life of me how to set the tax.

Thanks for your help!


回答1:


This is how its done.

the following code will setup a paypal express purchase for 2 items that have different prices (5 and 10 $), plus added taxes (50 cents) and with no shipping or handling cost.

response = YOUR_PAYPAL_GAETWAY_NAME.setup_purchase(1550,
  :subtotal => 1500,
  :shipping => 0,
  :handling => 0,
  :tax => 50,
  :ip     => CLIENT_IP, # you might want to use "request.remote_ip" method from a controller to obtain this value

  :items => [
             {:name => 'ITEM_NAME_1', :description => 'ITEM_DESC_1', :amount => 500, :quantity => 1}, 
             {:name => 'ITEM_NAME_2', :description => 'ITEM_DESC_2', :amount => 1000, :quantity => 1}
            ],

  :return_url        => 'http://SOME/URL',
  :cancel_return_url => 'http://MAYBE/ANOTHER/URL'
)

redirect_to YOUR_PAYPAL_GAETWAY_NAME.redirect_url_for(response.token)

NOTES:

  • All amounts must be in cents

  • All 4 options [:subtotal, :shipping, :handling, :tax] must be specified, if one or more is missing the rest will be ignored, if you dont need to set a certain option e.g. handling cost, just set it to zero like the example above, options set to zero won't appear on your paypal page.

  • :subtotal must equal to the total items price in cent, i.e. (item1 * quantity of item1) + (item2 * quantity of item2) and so on...

  • The total amount of the order (set to 1550 in the code), must equal to :subtotal + :shipping + :handling + :tax otherwise paypal will return an error (invalid transaction)




回答2:


I just noticed how old this is - but if for any reason anyone is looking for the answer, it looks like it's supported now if it wasn't before.

By the looks of things you need to have all 4 ':subtotal, :shipping, :handling, :tax' available and all must add up to the total amount you've passed through as your first option.



来源:https://stackoverflow.com/questions/1550072/setting-tax-amount-in-active-merchant-paypal-express-checkout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!