2014-04-25 49 views
0

我尝试以编程方式创建一个贝宝订单,但我需要重定向键。Drupal商业创建paypal WPS订单以编程方式

// 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(即该函数创建它),以创建它:贝宝WPS模块从$命令 - >数据[“payment_redirect_key”]这样得到这个数据编程。任何帮助表示赞赏。

我的目标是绕过默认的Drupal的电子商务结算机制

回答

0

我试图做的,没有运气一样,但我发现创建payment_redirect_key地方。您可以发现它在功能commerce_payment_redirect_pane_checkout_form在商业/模块/ commerce_payment /包括/ commerce_payment.checkout_pane.inc功能commerce_payment_redirect_pane_checkout_form,的当前版本(http://cgit.drupalcode.org/commerce/tree/modules/payment/includes/commerce_payment.checkout_pane.inc#n360

基本上线360,是这样的:

$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); 
} 
相关问题