Invia informazioni sull'ordina a un gateway di pagamento di terze parti
Domanda
Devo effettuare un nuovo modulo di pagamento che reindirizza a un gateway di pagamento di terze parti.
Quando il cliente Fare clic sul pulsante Paga I parametri post (Dettagli ordine) devono essere inviati al gateway. (E poi dopo il pagamento di successo / disinfettante, il cliente deve essere reindirizzato a una pagina di successo / annullamento rispettivamente.)
Secondo le istruzioni fornite dal fornitore del gateway 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>
.
Dal momento che la mia conoscenza in Magento è un po 'limitata, ho problemi a tradurre questo in un modulo magento funzionante.
Durante la ricerca ho trovato diverse soluzioni posible, ma non sono sicuro di quale sia quella giusta (e come implementarle):
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;
}
.
ecc. Ecc.
So che non è una domanda specifica, ma eventuali linee guida su come potrei ottenere questo il modo giusto?
Modifica
A seguito di alcuni tutorials ho creato un modulo di pagamento che è attualmente simile a questo: Payment Gateway
Saluti ...
Soluzione
<?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>
.
E così via con il resto dei campi del modulo ...