woocommerce 用のカスタム支払いゲートウェイを統合しました。正常に完了し、成功/失敗を出力し、カートを空にするとともに正しくリダイレクトすることができます。
function check_pg_response($order_id)
{
global $woocommerce;
$msg['class'] = 'error';
$msg['message'] = $this->settings['error_msg']." - Error: No Response From Payment Gateway.";
if (isset($_REQUEST['msg'])){
$response = $_REQUEST['msg'];
$response_data = array();
$resp = explode("|", $response);
$dataSize=sizeof($resp);
for($i = 0; $i < $dataSize; $i++)
{
$information=explode('=',$resp[$i]);
if($i==0) $txn_status=$information[1]; //001
if($i==1) $txn_msg=$information[1]; // success or failure
if($i==2) $txn_err_msg=$information[1]; // canceled by user
if($i==3) $txn_ref=$information[1];
if($i==4) $bank_cd=$information[1];
if($i==5) $txn_id=$information[1];
if($i==6) $txn_amt=$information[1];
if($i==7) $txn_time=$information[1];
}
}
if($order -> status !=='completed'){
$order_id = (int) $order_id;
$order = new WC_Order( $order_id );
if ($txn_msg=='success'){
$transauthorised = true;
$msg['message'] = $this->settings['success_msg'];
$msg['class'] = 'success';
if ($order->status != 'processing') {
$order->payment_complete();
$order->update_status('completed', __('Payment Successful.', 'wptut'));
$order->add_order_note('PG ID: '.$clnt_txn_ref.'<br/> Transaction ID: '.$tpsl_txn_id.'<br/>Bank CD: '.$tpsl_bank_cd);
$woocommerce -> cart -> empty_cart();}
}
else if($txn_msg=='failure'){
$msg['class'] = 'error';
$msg['message'] = $this->settings['declined_msg']." - Error: Payment Gateway Declined order.";
$order->update_status('failed', __('Payment has been cancelled.', 'wptut'));
$order->add_order_note('PG payment failed<br/>Techprocess ID: '.$txn_ref.'<br/>Payment Gateway Message: '.$txn_err_msg);
$woocommerce -> cart -> empty_cart();
}else{
$msg['class'] = 'error';
$msg['message'] = $this->settings['error_msg']." - Error: Unknown Error";
}
if ($transauthorised == false) {
$order->update_status('failed');
$order->add_order_note($msg['message']);
}
}
if (function_exists('wc_add_notice')) {
wc_add_notice($msg['message'], $msg['class']);
} else {
if ($msg['class'] == 'success') {
$woocommerce->add_message($msg['message']);
} else {
$woocommerce->add_error($msg['message']);
}
$woocommerce->set_messages();
}
$redirect_url = get_permalink(woocommerce_get_page_id('myaccount'));
wp_redirect($redirect_url);
exit;
} }