我必须制作一个新的付款模块,重定向到第三方支付网关。

当客户单击Pay按钮时,需要将帖子参数(订单详细信息)发送到网关。 (然后在成功/不成熟的付款后,客户需要分别被重定向到成功/取消页面。)

根据网关提供商An easy way to implement this functionality is to insert fields of type hidden at the e-shop payment form. These fields would contain values about the merchant, amount, payment details etc. For example:

给出的说明
<form action="https://www.gateway.com/.../" method="post" ID="Form1">
<input type="hidden" id="AmountToPay" name="AmountToPay" value="amount"/>
<input type="hidden" id="AmountCurrency" name="AmountCurrency" value="currency"/>
<input type="hidden" id="Details1" name="Details1" value="details"/>
<input type="hidden" id="Details2" name="Details2" value="orderID"/>
<input type="hidden" id="PayToMerchant" name="PayToMerchant" value="merchantID"/>
<input type="hidden" id="MerchantName" name="MerchantName" value="merchant"/>
<input type="hidden" id="PaymentOKURL" name="PaymentOKURL" value="https://shop.com/e-shopOK.html"/>
<input type="hidden" id="PaymentFailURL" name="PaymentFailURL" value="https://eshop.com/e-shopCancel.html"/>
</form>
. 自从我的Magento知识有些有限,我无法将其翻译成一个工作的Magento模块。

在研究时,我发现了几种Posible解决方案,但我不确定哪一个是正确的一个(以及如何实现它们):

1.

$client = new Varien_Http_Client('http://www.example.com/');
$client->setMethod(Varien_Http_Client::POST);
$client->setParameterPost('name', $name);
$client->setParameterPost('address', $address);
//more parameters
try{
    $response = $client->request();
    if ($response->isSuccessful()) {
        echo $response->getBody();
    }
} catch (Exception $e) {
}
.

2.

public function automatic(Varien_Event_Observer $observer) {
    $orderIds = $observer->getEvent()->getOrderIds();
    if (empty($orderIds) || !is_array($orderIds)) {
        return;
    }
    foreach ($orderIds as $eachOrderId) {
        $order = Mage::getModel('sales/order')->load($eachOrderId);
        //right our third party code
        client = new Zend_Http_Client();
        $client->setUri('http://eshop.com');
        $client->>setParameterPost(array(
        'api_key' => 'yourapi',
        'apikey' => 'xxxx',
        'message' => $message,
        'order_id' => $order_id,
        ...//more params
        ));
        $response = $client->request('POST');
        // Yet another way of preforming a POST request
        $client->setMethod(Zend_Http_Client::POST);
        if (!$response->isSuccessful()) {
            Mage::log($response);
        }
    }
    return $this;
}
.

等等。

我知道这不是一个非常具体的问题,但我如何以正确的方式达到这种指导方针?

编辑

在一些教程中,我创建了一些当前如下所示的付款模块:付款网关

问候...

有帮助吗?

解决方案

<?php $_order = new Mage_Sales_Model_Order();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$_order->loadByIncrementId($orderId);

$amountToPay = $_order->getBaseGrandTotal();
?>

<form action='https://www.gateway.com/.../' method='post'>
<input id='AmountToPay' name='AmountToPay' value="<?php echo $amountToPay; ?>" type='hidden' />
<input id='Details2' name='Details2' value='<?php echo $orderId; ?>' type='hidden' />
</form>
.

以及其余的表单字段...

许可以下: CC-BY-SA归因
scroll top