2014-04-25 50 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); 
} 
相關問題