无法使用braintree v.zero成功结账 -- commerce 领域 和 payment-gateways 领域 drupal 相关 的问题

Can't successfully Checkout using Braintree v.zero


0
vote

问题

中文

我将Braintree的V.Zero Drop-In UI作为付款方式和结帐表格集成。

我填写信用卡详细信息,然后单击"继续下一步" ,Ajax提交和Braintree同时加载。经过几秒钟,Braintree完成并返回支付Nonce。但是,表格不会继续提交。

输入图像描述 如何在表格之前先处理Braintree,以便我可以获得暂停的undle值?

模块代码

  /**  * Initializes the Braintree client library for use.  *  * @param $payment_method  *   The payment method instance containing the Braintree credentials to use to  *   submit API requests to Braintree.  */ function commerce_braintree_vzero_initialize($payment_method) {   require_once drupal_get_path('module', 'commerce_braintree_vzero') . '/braintree-php-2.37.0/lib/Braintree.php';    Braintree_Configuration::merchantId($payment_method['settings']['merchant_id']);   Braintree_Configuration::publicKey($payment_method['settings']['public_key']);   Braintree_Configuration::privateKey($payment_method['settings']['private_key']);   Braintree_Configuration::environment($payment_method['settings']['environment']); }  /**  * Implements hook_commerce_payment_method_info().  */ function commerce_braintree_vzero_commerce_payment_method_info() {   $payment_methods = array();    $payment_methods['commerce_braintree_vzero'] = array(     'title' => t('Braintree v.zero'),     'description' => t('Payment method using Braintree v.zero.'),     'active' => TRUE,   );    return $payment_methods; }  /**  * Returns the default settings for Braintree v.zero.  */ function commerce_braintree_vzero_default_settings() {   return array(     'merchant_id' => '',     'public_key' => '',     'private_key' => '',     'environment' => 'sandbox',   ); }  /**  * Payment method settings form.  *  * @param $settings  *   Default settings provided from rules  *  * @return array  *   Settings form array  */ function commerce_braintree_vzero_settings_form($settings) {   $form = array();    // Merge default settings into the stored settings array.   $settings = (array) $settings + commerce_braintree_vzero_default_settings();    $form['merchant_id'] = array(     '#type' => 'textfield',     '#title' => t('Merchant ID'),     '#default_value' => $settings['merchant_id'],     '#required' => TRUE,   );   $form['public_key'] = array(     '#type' => 'textfield',     '#title' => t('Public key'),     '#default_value' => $settings['public_key'],     '#required' => TRUE,   );   $form['private_key'] = array(     '#type' => 'textfield',     '#title' => t('Private key'),     '#default_value' => $settings['private_key'],     '#required' => TRUE,   );   $form['environment'] = array(     '#type' => 'radios',     '#title' => t('Braintree server'),     '#options' => array(       'sandbox' => ('Sandbox - use for testing, requires a Braintree Sandbox account'),       'production' => ('Production - use for processing real transactions'),     ),     '#default_value' => $settings['environment'],   );    return $form; }  /**  * Payment method callback: checkout form.  */ function commerce_braintree_vzero_submit_form($payment_method, $pane_values, $checkout_pane, $order) {   // Load Braintree vzero php library   commerce_braintree_vzero_initialize($payment_method);    $clientToken = Braintree_ClientToken::generate();    $form['test'] = array(     '#markup' => '<div id="asd"></div>' .     '<script src="https://js.braintreegateway.com/v2/braintree.js"></script><input type="submit">',   );    $form['testt'] = array(     '#type' => 'textfield',     '#title' => t('Test'),   );    drupal_add_js(array('vzero' => array('clientToken' => $clientToken)), 'setting');    // Load vzero.js.   $form['#attached']['js'] = array(     drupal_get_path('module', 'commerce_braintree_vzero') . '/vzero.js',   );    return $form; }  /**  * Payment method callback: checkout form submission.  */ function commerce_braintree_vzero_submit_form_submit($payment_method, $pane_form, $pane_values, $order, $charge) {   commerce_braintree_vzero_transaction($payment_method, $order, $charge);   drupal_set_message('success'); }  /**  * Creates an example payment transaction for the specified charge amount.  *  * @param $payment_method  *   The payment method instance object used to charge this payment.  * @param $order  *   The order object the payment applies to.  * @param $charge  *   An array indicating the amount and currency code to charge.  */ function commerce_braintree_vzero_transaction($payment_method, $order, $charge) {   $transaction = commerce_payment_transaction_new('commerce_braintree_vzero', $order->order_id);   $transaction->instance_id = $payment_method['instance_id'];   $transaction->amount = $charge['amount'];   $transaction->currency_code = $charge['currency_code'];   $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;    $transaction->message = 'Test message';    commerce_payment_transaction_save($transaction);   return $transaction; }   

js代码

  (function ($) {   Drupal.behaviors.vzero = {     attach: function (context, settings) {        if ($('#edit-commerce-payment-payment-method-commerce-braintree-vzerocommerce-payment-commerce-braintree-vzero', context).is(':checked')) {         console.log("LOADED " + $('#asd').length);         braintree.setup(settings.vzero.clientToken, "dropin", {           container: "asd",           paymentMethodNonceReceived: function (event, nonce) {             console.log('nonce received ' + nonce);             $('.form-item-commerce-payment-payment-details-testt input').val(nonce);              $('body').delegate('#edit-continue', 'click', function(event) {               event.preventDefault();               console.log('prevent submit');               return false;             });           }         });       }       else {         console.log("NOT CHECKED");       }     }   } })(jQuery);   

注意:这是如果您想测试的完整模块。 https://github.com/leolandotan/commerce_braintree_vzero

英文原文

I'm integrating Braintree's v.zero drop-in ui as a payment method and on the checkout form.

I fill-up the credit card details and click "Continue to next step", the ajax submit and Braintree loads simultaneously. After a couple of seconds, Braintree finishes and returns the payment nonce. However, the form doesn't continue it's submission.

enter image description here How can I process Braintree first before the form so that I can get the payment nonce value?

Module code

/**  * Initializes the Braintree client library for use.  *  * @param $payment_method  *   The payment method instance containing the Braintree credentials to use to  *   submit API requests to Braintree.  */ function commerce_braintree_vzero_initialize($payment_method) {   require_once drupal_get_path('module', 'commerce_braintree_vzero') . '/braintree-php-2.37.0/lib/Braintree.php';    Braintree_Configuration::merchantId($payment_method['settings']['merchant_id']);   Braintree_Configuration::publicKey($payment_method['settings']['public_key']);   Braintree_Configuration::privateKey($payment_method['settings']['private_key']);   Braintree_Configuration::environment($payment_method['settings']['environment']); }  /**  * Implements hook_commerce_payment_method_info().  */ function commerce_braintree_vzero_commerce_payment_method_info() {   $payment_methods = array();    $payment_methods['commerce_braintree_vzero'] = array(     'title' => t('Braintree v.zero'),     'description' => t('Payment method using Braintree v.zero.'),     'active' => TRUE,   );    return $payment_methods; }  /**  * Returns the default settings for Braintree v.zero.  */ function commerce_braintree_vzero_default_settings() {   return array(     'merchant_id' => '',     'public_key' => '',     'private_key' => '',     'environment' => 'sandbox',   ); }  /**  * Payment method settings form.  *  * @param $settings  *   Default settings provided from rules  *  * @return array  *   Settings form array  */ function commerce_braintree_vzero_settings_form($settings) {   $form = array();    // Merge default settings into the stored settings array.   $settings = (array) $settings + commerce_braintree_vzero_default_settings();    $form['merchant_id'] = array(     '#type' => 'textfield',     '#title' => t('Merchant ID'),     '#default_value' => $settings['merchant_id'],     '#required' => TRUE,   );   $form['public_key'] = array(     '#type' => 'textfield',     '#title' => t('Public key'),     '#default_value' => $settings['public_key'],     '#required' => TRUE,   );   $form['private_key'] = array(     '#type' => 'textfield',     '#title' => t('Private key'),     '#default_value' => $settings['private_key'],     '#required' => TRUE,   );   $form['environment'] = array(     '#type' => 'radios',     '#title' => t('Braintree server'),     '#options' => array(       'sandbox' => ('Sandbox - use for testing, requires a Braintree Sandbox account'),       'production' => ('Production - use for processing real transactions'),     ),     '#default_value' => $settings['environment'],   );    return $form; }  /**  * Payment method callback: checkout form.  */ function commerce_braintree_vzero_submit_form($payment_method, $pane_values, $checkout_pane, $order) {   // Load Braintree vzero php library   commerce_braintree_vzero_initialize($payment_method);    $clientToken = Braintree_ClientToken::generate();    $form['test'] = array(     '#markup' => '<div id="asd"></div>' .     '<script src="https://js.braintreegateway.com/v2/braintree.js"></script><input type="submit">',   );    $form['testt'] = array(     '#type' => 'textfield',     '#title' => t('Test'),   );    drupal_add_js(array('vzero' => array('clientToken' => $clientToken)), 'setting');    // Load vzero.js.   $form['#attached']['js'] = array(     drupal_get_path('module', 'commerce_braintree_vzero') . '/vzero.js',   );    return $form; }  /**  * Payment method callback: checkout form submission.  */ function commerce_braintree_vzero_submit_form_submit($payment_method, $pane_form, $pane_values, $order, $charge) {   commerce_braintree_vzero_transaction($payment_method, $order, $charge);   drupal_set_message('success'); }  /**  * Creates an example payment transaction for the specified charge amount.  *  * @param $payment_method  *   The payment method instance object used to charge this payment.  * @param $order  *   The order object the payment applies to.  * @param $charge  *   An array indicating the amount and currency code to charge.  */ function commerce_braintree_vzero_transaction($payment_method, $order, $charge) {   $transaction = commerce_payment_transaction_new('commerce_braintree_vzero', $order->order_id);   $transaction->instance_id = $payment_method['instance_id'];   $transaction->amount = $charge['amount'];   $transaction->currency_code = $charge['currency_code'];   $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;    $transaction->message = 'Test message';    commerce_payment_transaction_save($transaction);   return $transaction; } 

JS code

(function ($) {   Drupal.behaviors.vzero = {     attach: function (context, settings) {        if ($('#edit-commerce-payment-payment-method-commerce-braintree-vzerocommerce-payment-commerce-braintree-vzero', context).is(':checked')) {         console.log("LOADED " + $('#asd').length);         braintree.setup(settings.vzero.clientToken, "dropin", {           container: "asd",           paymentMethodNonceReceived: function (event, nonce) {             console.log('nonce received ' + nonce);             $('.form-item-commerce-payment-payment-details-testt input').val(nonce);              $('body').delegate('#edit-continue', 'click', function(event) {               event.preventDefault();               console.log('prevent submit');               return false;             });           }         });       }       else {         console.log("NOT CHECKED");       }     }   } })(jQuery); 

Note: This here is the complete module if you would like to test. https://github.com/leolandotan/commerce_braintree_vzero

     

回答列表

1
 
vote

此补丁成功为vzero https://www.drupal.org/node/2449881。

 

this patch successfully adds support for Vzero https://www.drupal.org/node/2449881.

 
 

相关问题

0  在Drupal Commerce中添加内容参考产品  ( Add content reference to product in drupal commerce ) 
如何向商务产品添加内容引用? 考虑您的产品是手机,而且您不想输入手机的添加规格,只需制作内容类型的手机,使手机内容并在产品中引用。 有没有更好的办法?因为我不能引用产品中的内容。 ...

0  规则component_rules_payment_component_delete_all定义在哪里?  ( Where is the rule component rules payment component delete all defined ) 
在商业kickstart 2.似乎无法找到此代码。 ...

1  商业/规则为某种SKU的每10个产品添加额外的产品(或额外费用)  ( Commerce rules adding an additional product or extra fee for every 10 produc ) 
我的公司正试图为Drupal Commerce实施一个复杂的定价方案,如下所示: 为您的每10件产品自动购买产品B(或总价格增加10美元) 所以在购物车中的1-10型产品,总成本应该是产品的成本*的数量,加上1份产品B(10美元) 和11-20型产品中的A型购物车它应该是产品的成本*的数量,加上2个产品B(20美元)...

1  如何验证和存储Drupal Commerce结帐日期和时间  ( How to validate and store drupal commerce checkout date and time ) 
我正在研究餐饮服务Drupal Commerce网站,其中每个餐饮公司拥有开放时间(例如:晚上8点至11点30点),具有开放,繁忙和封闭的状态。目的是,当用户选择日期,事件时间和购买时(添加到购物车并检查)时,它应该检查所输入的时间在状态为开放的开放时间之间有效。所选时间和日期应保持并显示在所有结账操作和订单中。 是...

0  为什么我的价格在搜索索引的视图中显示出未格式化的(次要单位)?  ( Why are my prices showing up as unformatted minor units in a view on a search ) 
在这里奇怪,我正在尝试搜索API,搜索DB和视图。我有一个基于商务产品的看法。视图有效,以及它的大多数方面(但这是另一个故事)。 我跑进了一个奇怪的问题。我使用Search API和Search_DB基于搜索索引的视图。我可以访问我索引的所有字段,但价格被呈现为次要单位的未格式化价格。它被拉为"索引商业产品价格" ...

1  如何在订单总现场视图中更改价格组件订单  ( How to change the price componnents order in the order total field view ) 
我有一个商务网站,我想在订单视图页面中更改总订单字段的价格组件顺序。 在"编辑" 订单页面中,上一个添加的行项 - 在我的情况下,我将它们手动添加 - 成为价格组件字段中的第一个,我想要逆。 我没有找到任何视图来编辑添加的行项目订单。所以我想问一下是否有办法做到这一点。 ...

0  特色产品 - Drupal Commerce  ( Featured product drupal commerce ) 
我有这个问题:我有一个产品显示一个"特色" 复选框。 我想选择这个"特色" 复选框时,在添加到购物车时要增加产品的价格。 所以:正常产品将花费100美元,如果选择的价格是+50(150美元)。 这可以用规则吗?如果是这样,怎么样? 谢谢 ...

0  查看(仅阅读)访问Drupal Commerce - 订单  ( View read only access for drupal commerce orders ) 
我已将2个属性添加到我的Drupal Commerce Orders Fields - Fivestar评级&amp;审查。我的客户需要我在股票格式的主页"Testimonial" 部分中展示评级和评论。我能够成功将评级+审核集成到订单中,并为具有admin的角色的用户显示推荐部分。 以下图片显示我的配置: ...

0  缺少产品类型设置中的CET_ENABLE字段(Commerce事件票)  ( Missing cet enable field in product type settings commerce event ticket ) 
我已经安装了 Commerce事件票,以及任何要求,并启用它。我看到以下列下列 description admin/modules : 允许为商业购买生成票证(带唯一条形码)。 版本:7.x-1.0-beta3 要求:Entity API(已启用),Commerce(已启用),系统(已启用),规则 (启用)...

0  当我添加到订单中选择的送货程序项时,它重复了订单  ( When i add the shipping line item that was selected to the orders view in commer ) 
这似乎与订单有多少产品,因为从订单中添加了这个送货线项它显示它显示适用于的每个产品。 是否有一种方法可以在视图中更改设置,仅显示显示送货选项的一个列表并隐藏所有重复项? ...

1  如何为自定义或现有实体添加预先提出的钩子,如商务单?  ( How to add a predelete hook for a custom or existing entity like commerce order ) 
我需要在 drupal commerce 订单中删除。 在实体API页面上,我发现了一个修补程序哪个以某种方式添加了预先添加的钩子,或者至少使实体调用那些。但是,不知何故,我无法使用以下代码来工作: /** * update stock when deleting an order */ function ...

0  如何以编程方式更新商务产品  ( How to update commerce product programatically ) 
$product_load = commerce_product_load(456); $product_load->uid = $GLOBALS['user']->uid; $product_load->example[LANGUAGE_NONE][0]['tid'] = 123; commer...

0  产品价格格式化器  ( Product price formatter ) 
在我的店铺网站上,在列出的每一个产品中,我们可以只列出美元金额,即80.00美元(例如。) - 并删除所下面的默认货币(例如,AUD)和(GST(ECC))文本? 如何格式化价格? ...

0  如何将产品字段注入产品显示?  ( How to inject a product field to product display ) 
我在产品上添加了一个字段。我希望在被引用的产品显示上显示相同的字段.I需要用代码执行此操作。 我怎样才能做到这一点? 谢谢 ...

1  商务 - 电子邮件订单项作为视图未显示它匿名发送时  ( Commerce email order items as a view doesnt show up when its sent by anonymous ) 
当我使用它时, <?php function bobr_commerce_email_order_items($variables) { // Get order wrapper .$order_wrapper = $variables['commerce_order_wrapper']; // Ge...

1  显示产品领域两次  ( Display product field twice ) 
我只想在页面上显示两次产品详细信息。 我使用 display suite 用于在节点(产品显示)上显示所有字段,并用于显示两次字段,我想使用动态字段。它让我选择这个字段,但是当我查看我的节点时,我得到500错误。 有人可以帮帮我吗? 非常感谢您的帮助! ...

1  商务优惠券,折扣和税收未出现在结账审查页面上  ( Commerce coupons discounts and tax not appearing on checkout review page ) 
所以我能够在结账页面上申请优惠券。基于数量的折扣也出现在结账页面上。作为基于基于国家的销售税。但是,当您从那里继续,您选择送货服务,然后继续结账审核。此时,优惠券已经消失,折扣和税收也是如此。 输入的优惠券仍然显示在表单中,但授予金额现在为0.00美元。 我正在失去理智,因为我正在处理这个网站时,这是在这开始发生...

2  如何从史书签中重新发送相同的时事通讯?  ( How to resend same newsletter from simplenews ) 
我在drupal 7中使用Simplenews模块。我还有工作邮件系统以及Cron系统。我想重新发送先前已发送的时事通讯。每次都要重新发送,我不想编辑数据库。我想使用用户界面本身发送时事通讯。 我尝试编辑 simplenews.module 和 simpleNews.admin.inc 文件。 我编辑了 simple...

1  不同价格在购物车形式和购物车摘要在商业价格表中的概要视图  ( Different prices in shopping cart form and shopping cart summary views in commer ) 
我有一个问题表模块,我希望你能在这个问题上支持我。由于我有一些不同价格的产品,根据商品价格表模块,一切正常,除"购物车摘要视图" 外,只能显示基本价格,并不按数量显示计算价格。此外,我在admin&gt中发现了规则"覆盖价格表" 。Configuration&gt;似乎它似乎对"购物车摘要视图" 似乎没有任何影响! ...

1  如何运行commerce_order_save()而不触发任何规则?  ( How to run commerce order save without triggering any rules ) 
我需要在循环中的几个订单上运行 commerce_order_save() ,但不触发任何规则。 是可能的吗? ...




© 2021 it.wenda123.org All Rights Reserved. 问答之家 版权所有


Licensed under cc by-sa 3.0 with attribution required.