繁体   English   中英

Drupal Commerce以编程方式创建Paypal WPS订单

[英]Drupal commerce create paypal wps order programmatically

我正在尝试以编程方式创建贝宝订单,但我需要重定向键。 贝宝WPS模块从$ order-> data ['payment_redirect_key']获取此数据,如下所示:

// Return to the payment redirect page for processing successful payments
'return' => url('checkout/' . $order->order_id . '/payment/return/' . $order->data['payment_redirect_key'], array('absolute' => TRUE)),

但是我找不到在哪里创建payment_redirect_key(即哪个函数创建它)以便以编程方式创建它。 任何帮助表示赞赏。

我的目标是绕过默认的Drupal Commerce Checkout机制

我正在尝试做同样没有运气的方法,但是我发现了创建了payment_redirect_key的位置。 您可以在commerce / modules / commerce_payment / includes / commerce_payment.checkout_pane.inc函数commerce_payment_redirect_pane_checkout_form,当前版本的第360行中的commerce_payment_redirect_pane_checkout_form函数中找到它( http://cgit.drupalcode.org/commerce/tree/modules/payment /includes/commerce_payment.checkout_pane.inc#n360

基本上是这样的:

$order->data['payment_redirect_key'] = drupal_hash_base64(time());
commerce_order_save($order);

编辑

经过几天的努力,我仅用几行代码就找到了解决方案。 我将此功能用作菜单项的页面回调(类似于product /%sku)。 这是代码:

<?php
function custom_module_create_order($sku) {
  global $user;
  $product = commerce_product_load_by_sku($sku);
  $order = ($user->uid) ? commerce_order_new($user->uid, 'checkout_checkout') : commerce_cart_order_new();
  // Save to get the Order ID.
  commerce_order_save($order);

  $line_item = commerce_product_line_item_new($product, 1, $order->order_id);
  commerce_line_item_save($line_item);
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $order_wrapper->commerce_line_items[] = $line_item;

  // Select here the payment method. Usually something like:
  // [module_name]|commerce_payment_[module_name]
  $order->data['payment_method'] = 'commerce_sermepa|commerce_payment_commerce_sermepa';
  commerce_order_save($order);

  // Set status to order checkout to go to the payment platform redirect.
  commerce_order_status_update($order, 'checkout_payment');

  drupal_goto('checkout/' . $order->order_id);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM