Drupal commerce以编程方式创建paypal wps命令

时间:2014-04-25 08:51:01

标签: drupal paypal drupal-7 commerce

我试图以编程方式创建一个paypal订单,但我需要重定向键。 paypal 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商业结帐机制

1 个答案:

答案 0 :(得分: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);
}