2017-01-23 81 views
1

嗨,我很好奇如何最好地計算包括產品預結算增值稅的價格。目前我發現的唯一方法是創建一個包含該項目的訂單,然後從訂單中提取稅金和價格。但是,這會產生大量的冗餘訂單,並且似乎是次優的。有沒有辦法做這個計算而不創建一個訂單?計算包含稅的條紋taxamo價格的最佳方式

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

您可以使用Taxamo的API Calculate tax端點(Ruby客戶端庫文件爲available)。

請注意,如果設置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 
相關問題