如何使用vue-paypal-checkout生成商品列表?

时间:2018-10-30 18:32:33

标签: vue.js paypal paypal-sandbox vue-paypal-check

我正在尝试从Paypal结帐请求中生成商品列表响应。我正在尝试在 for in 循环中使用数据对象和一些计算出的属性来动态地执行此操作。据我了解,我的items_list将始终需要是一个数据变量,而不是硬编码数组。

这是我的模板元素:

<div v-bind:key="plan.key" v-for="plan in plans" >  
    <PayPal 
        :amount="plan.price" // all good
        currency="GBP" // all good
        :client="credentials" // all good
        env="sandbox" // all good
        :items="[plan]"  // this is NOT working
        @payment-authorized="payment_authorized_cb" // all good
        @payment-completed="payment_completed_cb" // all good
        @payment-cancelled="payment_cancelled_cb"   // all good  
   >
   </PayPal> 
</div>

这是我脚本上的数据对象:

 plans: {
        smallPlan: {
            name: 'Small Venue',
            price: '6',
        },
        mediumPlan: {
            name: 'Medium Department',
            price: '22',

        }, 
}
payment_completed: {
    payment_completed_cb() {
    }
},
payment_authorized: {
    payment_authorized_cb() {
    }
},
payment_cancelled: {
    payment_cancelled_cb() {
    }
},

这是我的方法:

methods: {
payment_completed_cb(res, planName){
    toastr.success("Thank you! We'll send you a confirmation email soon with your invoice. ");
    console.log(res);  
},
payment_authorized_cb(res){
    console.log(res); 
},
payment_cancelled_cb(res){
    toastr.error("The payment process has been canceled. No money was taken from your account.");
    console.log(res); 
},

有关Vue-paypal-checkout的文档,请点击https://www.npmjs.com/package/vue-paypal-checkout

如果我不添加项目列表:项目,则一切正常:

  
    

{“ id”:“ PAY-02N9173803167370DLPMKKZY”,“ intent”:“ sale”,“ state”:“ approved”,“ cart”:“ 90B34422XX075534E”,“ create_time”:“ 2018-10-30T18:39 :51Z“,”付款人“:{”付款方式“:”贝宝“,”状态“:”已验证“,”付款人信息“:{”电子邮件“:” joaoalvesmarrucho-buyer@gmail.com“,”名字“:”测试“,” middle_name“:” test“,” last_name“:” buyer“,” payer_id“:” JCZUFUEQV33WU“,” country_code“:” US“,” shipping_address“:{” recipient_name“:” test Buyer“,” line1 “:” 1 Main St“,” city“:” San Jose“,” state“:” CA“,”邮政编码“:” 95131“,” country_code“:” US“}}},”交易“:[{ “ amount”:{“ total”:“ 245.00”,“ currency”:“ GBP”,“ details”:{}},“ item_list”:{},“ related_resources”:[{“ sale”:{“ id” :“ 2RA79134UX2301839”,“状态”:“待处理”,“付款方式”:“ INSTANT_TRANSFER”,“保护资格”:“ ELIGIBLE”,“父母付款”:“ PAY-02N9173803167370DLPMKKZY”,“创建时间”:“ 2018-10-30T18: 39:50Z“,” update_time“:” 2018-10-30T18:39:50Z“,” reason_code“:” RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION“,” amount“:{” total“:” 245.00“,” currency“:” GBP“, “详细信息”:{“小计”:“ 245.00”}}}}]] }]}

  

但是,如果我添加:items =“ [plan]”,则会收到此错误消息:

  
    

未捕获的错误:错误:发布https://www.sandbox.paypal.com/v1/payments/payment的请求失败,出现400错误。相关编号:19238526650f5、19238526650f5

         

{         “ name”:“ VALIDATION_ERROR”,         “细节”: [             {                 “ field”:“ transactions.item_list.items.item_key”,                 “ issue”:“未为此资源类型定义此字段名称”             }         ],         “ message”:“无效的请求-查看详细信息”,         “ information_link”:“ https://developer.paypal.com/docs/api/payments/#errors”,         “ debug_id”:“ 19238526650f5”

  

有什么想法吗?

如果您碰巧知道,有没有一种方法可以使用Vue-paypal-checkout出售/实现订阅,而不是一次性交易?

非常感谢

0 个答案:

没有答案