I'm developing a payment gateway for WooCommerce with my client's bank that provides an API and actually I can process the payment correctly, but I need to show the transaction receipt in the thankyou page, actually I know how to modify that template, but what I need at this moment is use the response from the bank API in the template for show the receipt that is generated by the bank and is sent in the response body, this is how I actually process the payment:
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;
}
}
}
until there the code works just great, I need some help is in the redirect part,
// Redirect to the thank you page
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
I need send this response to that page so I can extract the voucher (transaction receipt) to show it to the customer. this is a response I'm actually getting for the bank 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
}