简体   繁体   中英

Drupal commerce create paypal wps order programmatically

I m trying to create a paypal order programmatically but I need the redirection key. The paypal WPS module gets this data from the $order->data['payment_redirect_key'] like this:

// 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)),

However i cannot find where the payment_redirect_key is created (ie which function creates it) in order to create it programmatically. Any help is appreciated.

My goal is to bypass the default drupal commerce checkout mechanism

I'm trying to do the same with no luck yet, but I find out where the payment_redirect_key is created. You can found it in the function commerce_payment_redirect_pane_checkout_form in the commerce/modules/commerce_payment/includes/commerce_payment.checkout_pane.inc function commerce_payment_redirect_pane_checkout_form, line 360 of the current version ( http://cgit.drupalcode.org/commerce/tree/modules/payment/includes/commerce_payment.checkout_pane.inc#n360 )

Basically, is this:

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

EDIT

After a couple days working on this, I found the solution in just a few lines of code. I use this function as a page callback of a menu item (something like product/%sku). Here is the code:

<?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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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