0

我正在尝试以编程方式创建贝宝订单,但我需要重定向键。贝宝 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 商务结帐机制

4

1 回答 1

0

我正在尝试做同样的事情,但还没有运气,但我发现了 payment_redirect_key 的创建位置。您可以在 commerce/modules/commerce_payment/includes/commerce_payment.checkout_pane.inc 函数 commerce_payment_redirect_pane_checkout_form 的 commerce_payment_redirect_pane_checkout_form 函数中找到它,当前版本的第 360 行(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);
}
于 2015-04-15T11:28:21.973 回答