2017-05-01 13 views
0

我在使用Drop-in功能的沙盒模式中嘗試Braintree。 我使用現有的customerID創建客戶端令牌。但是,當我做transaction.sale調用這個customerId和期權storeInVault = true提示錯誤以下錯誤:Braintree沙箱transaction.sale給出錯誤:「銷售客戶ID已被採納」

Sale Customer ID has already been taken.

按照它應該更新與支付現時客戶的文檔。

下面是代碼:

gateway.transaction.sale({ 
    amount: '10.00', 
    paymentMethodNonce: nonceFromTheClient, // Generated nonce passed from client 
    customer: { 
    id: 232057823, //this customer exist in the vault 
    email : user.emails[0].address 
    }, 
    options: { 
    submitForSettlement: true, 
    storeInVault: true 
    //storeInVaultOnSuccess: true 
    } 
}, function (err, result) { 
    if (err) { 
    console.log(err); 
    } else { 
    if (result.success) { 
     return result.success; 
    } else { 
      console.log('ERR Sale '+result.message); 
      return result.success; 
    } 
    } 
}); 

我使用流星與包patrickml:braintree

回答

1

您看起來使用的是Braintree Transaction Sale API Call,其中包含storeInVault:true選項。這樣做是使用包含的付款方法隨機數創建一個事務,並試圖創建一個客戶ID爲232057823,這就是爲什麼你遇到了這個錯誤。

如果您的目標是簡單更新現有客戶,那麼您需要使用Customer Update API call

+0

我認爲這是我可能要做的。但根據文檔:**現有客戶使用新的付款方式** 要將此交易的付款方式與現有客戶關聯,請將customerId與options.storeInVault或options.storeInVaultOnSuccess一起傳遞爲true。 的Node.js 'gateway.transaction.sale({ 量: 「10.00」, paymentMethodNonce:nonceFromTheClient, 客戶ID: 「theCustomerId」, 選項:{ storeInVaultOnSuccess:真 } },功能(ERR,結果){ });' –

+0

該文檔是正確的,但我可以看到混淆。您在客戶選項中嵌套'id'屬性。在您已鏈接的示例中,customerId屬性在頂層指定。 – ThinkAboutIt

+1

尤里卡瞬間!良好的捕捉,它總是有助於有第二雙眼睛!非常感謝。 –