2017-01-23 12 views
1

こんにちは私は製品の事前チェックアウトのための付加価値税を含む価格を計算する最良の方法が不思議です。現在私が見つけた唯一の方法は、商品を含む注文を作成し、その注文から税金と価格を取り出すことです。しかし、これは多くの冗長な注文を作り、準最適と思われる。注文を作成せずにこの計算を行う方法はありますか?税を含むストライプタクシー価格を計算する最良の方法

def get_price 
    location = current_user.location 
    location_data = APP_CONFIG['country_list'][location] 
    currency = location_data['currency'] 
    country_code = location_data['code'] 
    product_id = APP_CONFIG['stripe_reconstruction_ids'][currency] 
    product = Stripe::Product.retrieve(product_id) 
    product_sku = product['skus']['data'][0]['id'] 
    ip = request.remote_ip 

    order = Stripe::Order.create(
    :currency => currency, 
    :customer => current_user.stripe_id, 
    :items => [ 
     { 
      :type => 'sku', 
      :parent => product_sku, 
      :quantity => 1, 
      :currency => currency 
     } 
    ], 
    :email => current_user.email, 
    :metadata => { 
     :buyer_ip => ip, 
     :billing_country_code => country_code, 
     :product_type => 'e-service' 
    } 
) 


    render :json => order, :status => 200 and return 


rescue => error 
    logger.error error.message 
    render :json => { message: "Could not fetch the correct price." }, :status => 500 and return 
end 

UPDATE

ストライプのサポートに話した後、私の提案は、現時点ではこれを行うための最善の方法であるように思われます。私は、開発者が注文にフラグを設定して、後で決済に使用されない注文を作成しないようにするための料金設定情報であることがうれしいと提案しました。彼らは、この提案を開発者に提供すると述べた。将来これを行うためのより良い方法があるでしょう。

答えて

3

エンドポイント(Rubyクライアントlibはavailable)のTaxamo API Calculate taxを使用できます。

buyer_ipプライベートトークンを使用する必要がある場合は、それ以外のフィールドは無視されます。

例カールコール:

curl -X 'POST' -H "Content-Type: application/json" -d \ 
'{ 
     "transaction": { 
      "currency_code": "EUR", 
      "transaction_lines": [ 
       { 
        "custom_id": "line1", 
        "product_type": "e-service", 
        "amount": 100 
       } 
      ], 
      "billing_country_code": "SOME_COUNTRY_CODE", 
      "buyer_ip": "SOME_IP" 
     }, 
     "private_token": "YOUR_PRIVATE_TOKEN" 
    }' \ 
https://api.taxamo.com/api/v1/tax/calculate | python -m json.tool 
関連する問題