<?php
/**
DOCS:
https://api.netcash.co.za/inbound-payments/pay-now/pay-now-ecommerce/

Netcash will always send a response to the Notify URL - this is asynchronous and this is the URL that should be used to write the transaction status to the database.

The Accept and Deline URL's are just synchronous responses to keep the user updated on the status of the transaction and, if there is a time delay from the bank (security), then the Accept URL will not contain important information such as the Trace ID - that will be sent to the Notify URL when ready.
**/
require_once('netcash_common.php');


//SableDebug::debugfetch($_POST, LOG_FILE_NAME);
/**
NOTIFY URL:
===========

Field No:	Field Name:				Type		Description:
---------	----------------------	---------	-----------------------------------------------------------------------------------
1			TransactionAccepted		Boolean		“true” means the transaction was successful
2			CardHolderIpAddr		AN			This is the original IP the request was made from
3			RequestTrace			AN			This is a unique trace id for the transaction. This id can be used to retrieve 
												additional information from the 3rd Party transaction logs
4			Reference				AN			This is the unique reference that you sent Netcash in the original request
5			Extra1					AN			This is the extra field you sent up in the m4 variable when you made the request 
												that we return for you to integrate into your own system.
6			Extra2					AN			This is the extra field you sent up in the m5 variable when you made the request 
												that we return for you to integrate into your own system.
7			Extra3					AN			This is the extra field you sent up in the m6 variable when you made the request 
												that we return for you to integrate into your own system.
8			Amount					N			This is the amount that you sent Netcash in the original request
9			Method					N			1 Credit card
												2 			Bank EFT
												3 			Retail
												4 			Ozow
												5 			MasterPass
												6 			Visa Checkout
												7			Masterpass QR
10			ccToken					AN			Credit Card Vault GUiD
11			ccHolder				AN			Credit Cardholder name
12			ccMasked				AN			Masked Credit Card number
13			ccExpiry				N			Credit Card expiry date MMCCYY
**/
//if ($txnok && $success)
{
	$sql =	"update netcash_payment set 
			np_success = {$success}, 
			np_reason = '{$reason}', 
			reason_code = '{$trcdata['Method']}', 
			np_trace_id = '{$requestTrace}', 
			np_payment_type = {$method}, 
			np_description = '{$PayDescr}', 
			np_cardholder_name = '{$ccHolder}',
			np_card_no = '{$ccMasked}',
			np_card_expiry = {$expiryDate} 
			where (np_reference = '{$_POST['Reference']}')";

	$res = $sableDB->updateQuery($sql);
	
	/**
	$sql =	'update netcash_payment 
			set reason_code = '.intval($trcdata['Method']).' 
			where (np_user = '.$userCode.') and (np_date = "'.$payTs->format('Y-m-d H:i:s').'")';

	$res = $sableDB->updateQuery($sql);
	**/
	//SableDebug::debugfetch($res, LOG_FILE_NAME);	
}
