2017-08-09 217 views
1

使用node-recurly附加訂閱,我可以創建一個訂閱對象,並把它傳遞給recurly.subscriptions.create電話:創建使用節點recurly

const subscription = { 
     plan_code: plan.code, 
     currency: 'USD', 
     account: { 
     account_code: activationCode, 
     first_name: billingInfo.first_name, 
     last_name: billingInfo.last_name, 
     email: billingInfo.email, 
     billing_info: { 
      token_id: paymentToken, 
     }, 
     }, 
    }; 

我也想補充subscription_add_ons屬性,這,看着the documentation,應該成爲一系列附加組件。我試圖傳遞這樣的:

subscription_add_ons: [ 
     { 
      add_on_code: shippingMethod.servicelevel_token, 
      unit_amount_in_cents: parseFloat(shippingMethod.amount) * 100, 
     }, 
     ], 

服務器返回一個錯誤:

Tag <subscription_add_ons> must consist only of sub-tags named <subscription_add_on>

我嘗試這樣的:

subscription_add_ons: [ 
     { 
      subscription_add_on: { 
      add_on_code: shippingMethod.servicelevel_token, 
      unit_amount_in_cents: parseFloat(shippingMethod.amount) * 100, 
      }, 
     }, 
     ], 

回來這個錯誤: enter image description here

什麼在這種情況下通過訂閱的正確格式添加?

回答

2

正確格式爲:

subscription_add_ons: { 
     subscription_add_on: [{ 
      add_on_code: shippingMethod.servicelevel_token, 
      unit_amount_in_cents: parseFloat(shippingMethod.amount) * 100, 
     }], 
     }, 
+0

此作品爲1添加。任何想法如何用超過1添加完成此? – Rk220

+0

subscription_add_on是一個數組。嘗試在其中添加附加附加組件。 –

0

最後我做這個工作,其是否有1附加或多個加載項。 subscription_add_ons是一個可以包含1個或更多訂閱附加組件的數組。然後,我會在訂閱更新呼叫中發送詳細信息(以及其他信息)。這與您在原始文章中嘗試的內容類似,所以我不確定爲什麼這不適合您。

details.subscription_add_ons = [ 
    { subscription_add_on: {add_on_code: "stream", quantity: 3} }, 
    { subscription_add_on: {add_on_code: "hold", quantity: 2} } 
];