我正在与我客户的银行一起为WooCommerce开发一个支付网关,该网关提供了一个API,实际上我可以正确处理支付,但我需要在thankyou页面中显示交易凭证,实际上我知道如何修改该模板,但我现在需要的是在模板中使用来自银行API的响应来显示银行生成并发送到响应正文中的收据,这就是我实际处理付款的方式:
public function process_payment( $order_id ) {
global $woocommerce;
$order = wc_get_order($order_id);
$curl = curl_init();
$data = array(
"KeyId" => $this->private_key,
"PublicKeyId"=> $this->public_key,
"Amount" => $order->get_total(),
"Description" => "Some Description Here",
"CardHolder" => ($_POST[\'card-holder-same\'] == 1 ) ? $_POST[\'billing_first_name\']." ".$_POST[\'billing_last_name\'] : $_POST[\'cp_wc_cch_fname\']." ".$_POST[\'cp_wc_cch_lname\'] ,
"CardHolderID" => $_POST[\'cp_wc_cch_id\'],
"CardNumber" => $_POST[\'cp_wc_ccNo\'],
"CVC" => $_POST[\'cp_wc_cvv\'],
"ExpirationDate" => $_POST[\'cp_wc_expdate\'],
"StatusId" => $this->pay_type,
"IP" => $_SERVER[\'REMOTE_ADDR\'],
"OrderNumber" => $order->get_order_number()
);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.url/payment",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$resp = json_decode($response);
if($resp->success == 1){
$order->payment_complete();
$order->reduce_order_stock();
$order->add_order_note( \'Gracias su pago ha sido procesado Exitosamente!\', true );
$woocommerce->cart->empty_cart();
// Redirect to the thank you page
return array(
\'result\' => \'success\',
\'redirect\' => $this->get_return_url( $order )
);
}else {
print_r($order->get_user());
wc_add_notice( \'Intenta Nuevamente\', \'error\' );
return;
}
}
}
在代码正常工作之前,我需要在重定向部分得到一些帮助,
// Redirect to the thank you page
return array(
\'result\' => \'success\',
\'redirect\' => $this->get_return_url( $order )
);
我需要将此响应发送到该页面,以便提取凭证(交易凭证)并将其显示给客户。这实际上是我对银行API的回应。
{
"success": true,
"message": "Pago Aprobado",
"id": "57e25f73-85e2-40a4-aed1-3ad8012c2623",
"code": "201",
"reference": "794283",
"voucher": "\\r\\n<table style="background-color: white;">\\r\\n <tbody>\\r\\n <tr>\\r\\n <td>\\r\\n <div style="border: 1px solid #222; padding: 9px; text-align: center; max-width:255px" id="voucher">\\r\\n\\r\\n <style type="text/css">\\r\\n .normal-left {\\r\\n font-family: Tahoma;\\r\\n font-size: 7pt;\\r\\n text-align: left;\\r\\n }\\r\\n\\r\\n .normal-right {\\r\\n font-family: Tahoma;\\r\\n font-size: 7pt;\\r\\n text-align: right;\\r\\n }\\r\\n\\r\\n .big-center {\\r\\n font-family: Tahoma;\\r\\n font-size: 9pt;\\r\\n text-align: center;\\r\\n font-weight: 900;\\r\\n }\\r\\n\\r\\n .big-center-especial {\\r\\n font-family: Tahoma;\\r\\n font-size: 9pt;\\r\\n text-align: center;\\r\\n font-weight: 900;\\r\\n letter-spacing: .9em;\\r\\n }\\r\\n\\r\\n .big-left {\\r\\n font-family: Tahoma;\\r\\n font-size: 9pt;\\r\\n text-align: left;\\r\\n font-weight: 900;\\r\\n }\\r\\n\\r\\n .big-right {\\r\\n font-family: Tahoma;\\r\\n font-size: 9pt;\\r\\n text-align: right;\\r\\n font-weight: 900;\\r\\n }\\r\\n\\r\\n .normal-center {\\r\\n font-family: Tahoma;\\r\\n font-size: 7pt;\\r\\n text-align: center;\\r\\n }\\r\\n\\r\\n #voucher td {\\r\\n padding: 0;\\r\\n margin: 0;\\r\\n }\\r\\n </style>\\r\\n <div id="voucher">\\r\\n <table>\\r\\n <tr>\\r\\n <td colspan="4" class="normal-center">COPIA - CLIENTE</td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="4" class="big-center-especial">\\r\\n <br />\\r\\n BANESCO\\r\\n </td>\\r\\n </tr>\\r\\n\\r\\n <tr>\\r\\n <td colspan="4" class="big-center">\\r\\n <br />\\r\\n \\r\\n </td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="4" style="height: 8px;"></td>\\r\\n </tr>\\r\\n\\r\\n <tr>\\r\\n <td colspan="4" class="normal-left">TECNOLOGIA INSTAPAGO</td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="4" class="normal-left">DEMOSTRACI&#211;N</td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="4" class="normal-left">J-000000000</td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="4" style="height: 8px;"></td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="2" class="normal-left">000000000000</td>\\r\\n <td colspan="2" class="normal-right">000000000000</td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="1" class="normal-left">FECHA:</td>\\r\\n <td colspan="3" class="normal-left">00/00/00 00:00:00 PM</td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="1" class="normal-left">NRO CUENTA:</td>\\r\\n <td colspan="2" class="normal-left">000000******0000 </td>\\r\\n <td class="normal-right">'0'</td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td class="normal-left">NRO. REF.:</td>\\r\\n <td class="normal-left">000000</td>\\r\\n <td class="normal-right">LOTE:</td>\\r\\n <td class="normal-right">000</td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="1" class="normal-left">APROBACION: </td>\\r\\n <td colspan="3" class="normal-left">000000</td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="1" class="normal-left">SECUENCIA:</td>\\r\\n <td colspan="3" class="normal-left"></td>\\r\\n </tr>\\r\\n\\r\\n <tr>\\r\\n <td colspan="4" style="height: 8px;"></td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="4" class="big-center">\\r\\n <br />\\r\\n MONTO BS. 0,00\\r\\n </td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="4" style="height: 8px;"></td>\\r\\n </tr>\\r\\n <tr style="margin-top: 10px;">\\r\\n <td colspan="4" class="big-center">RIF: J-000000000</td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="4" style="height: 8px;"></td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="4" class="normal-left">\\r\\n <b>\\r\\n <br />\\r\\n </b>\\r\\n </td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="4" class="normal-left">\\r\\n <br />debito\\r\\n </td>\\r\\n </tr>\\r\\n <tr>\\r\\n <td colspan="1" class="normal-left">ID:</td>\\r\\n <td colspan="3" class="normal-left">000000000000000000</td>\\r\\n </tr>\\r\\n </table>\\r\\n </div>\\r\\n </div>\\r\\n </td>\\r\\n </tr>\\r\\n </tbody>\\r\\n</table>\\r\\n\\r\\n\\r\\n\\r\\n",
"ordernumber": "45289652",
"sequence": "794283",
"approval": "794283",
"lote": "794283",
"responsecode": "00",
"deferred": false,
"datetime": "11/8/2018 11:43:52 AM",
"amount": "1,258.43",
"authid": null,
"idmerchant": null,
"terminal": null
}