2016-10-17 33 views
1

我正在建立一個雙邊市場與RoR, ,我想用條紋來處理付款。紅寶石在鐵軌市場和條紋

我希望用戶做出請求並付款(但使用捕獲錯誤,以後再收費),並在提供服務的用戶接受或拒絕請求時收費(或取消)。

所以我到目前爲止已經完成:

.Submiting .creating一個數據庫中的新請求(用布爾statut)請求 。用戶可以有效與否

但現在我不知道如何記錄結果並更新此請求的法定條件,從而使得新的API調用更新付款。

任何人已經做到了嗎?

回答

1

首先,你capture集倒是create the chargefalse

charge = Stripe::Charge.create({ 
    amount: 1000, 
    currency: 'usd', 
    destination: 'acct_...', 
    application_fee: 200, 
    capture: false, 
}) 

如果收費成功,你會來救充電的ID(charge.id)在你的數據庫。

然後,如果交易被確認,你capture the charge這樣的:

# Retrieve charge_id from your database 
charge = Stripe::Charge.retrieve(charge_id) 
charge.capture 

如果交易被取消,你會通過refunding the charge發行授權:

# Retrieve charge_id from your database 
refund = Stripe::Refund.create({ 
    charge: charge_id, 
}) 

注意未收取費用爲automatically released after 7 days

在上面,我假設你正在創建收費through the platform,即與destination參數。如果您是不是收費directly on connected accounts,你需要修改使用Stripe-Account頭的請求:

# Create the charge directly on the connected account 
charge = Stripe::Charge.create({ 
    amount: 1000, 
    currency: 'usd', 
    application_fee: 200, 
    capture: false, 
}, {stripe_account: 'acct_...'}) 
# Save charge.id in your database 

# Capture the charge 
charge = Stripe::Charge.retrieve(charge_id, {stripe_account: 'acct_...'}) 
charge.capture 

# Release the uncaptured charge 
refund = Stripe::Refund.create({ 
    charge: charge_id, 
}, {stripe_account: 'acct_...'}) 
+0

非常感謝Ywain,我想試試 – Tomas

+0

感謝張貼在退款過程中的信息。它也適用於我。 – Dave