Created
December 28, 2017 16:20
-
-
Save mafam1024/56e6b6685e378261ae11ea959fba32a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!defined('EVENT_ESPRESSO_VERSION')) { | |
exit('No direct script access allowed'); | |
} | |
/** | |
* | |
* EEG_Mock_Onsite | |
* | |
* Just approves payments where billing_info[ 'credit_card' ] == 1. | |
* If $billing_info[ 'credit_card' ] == '2' then its pending. | |
* All others get refused | |
* | |
* @package Event Espresso | |
* @subpackage | |
* @author Mike Nelson | |
* | |
*/ | |
class EEG_New_Payment_Method_Offsite extends EE_Offsite_Gateway{ | |
/** | |
* This gateway supports all currencies by default. To limit it to | |
* only certain currencies, specify them here | |
* @var array | |
*/ | |
protected $_currencies_supported = EE_Gateway::all_currencies_supported; | |
/** | |
* Example of site's login ID | |
* @var string | |
*/ | |
protected $_login_id = null; | |
/** | |
* Whether we have configured the gateway integration object to use a separate IPN or not | |
* @var boolean | |
*/ | |
protected $_override_use_separate_IPN = null; | |
/** | |
* @return EEG_New_Payment_Method_Offsite | |
*/ | |
public function __construct() { | |
//if the gateway you are integrating with sends a separate instant-payment-notification request | |
//(instead of sending payment information along with the user) | |
//set this to TRUE | |
$this->set_uses_separate_IPN_request( true ) ; | |
parent::__construct(); | |
} | |
/** | |
* Override's parent so this gateway integration class can act like one that uses | |
* a separate IPN or not, depending on what is set in the payment methods settings form | |
* @return boolean | |
*/ | |
public function uses_separate_IPN_request() { | |
if( $this->_override_use_separate_IPN_request !== null ) { | |
$this->set_uses_separate_IPN_request( $this->_override_use_separate_IPN_request ); | |
} | |
return parent::uses_separate_IPN_request(); | |
} | |
/** | |
* | |
* @param arrat $update_info { | |
* @type string $gateway_txn_id | |
* @type string status an EEMI_Payment status | |
* } | |
* @param type $transaction | |
* @return EEI_Payment | |
*/ | |
public function handle_payment_update($update_info, $transaction) { | |
wp_mail('mrakor@gmail.com' , 'update info' , print_r($update_info , true)); | |
wp_mail('mrakor@gmail.com' , 'update 2' , print_r($_REQUEST , true)); | |
$payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['vpc_TransactionNo'] ); | |
if($payment instanceof EEI_Payment && isset( $update_info[ 'vpc_TxnResponseCode' ] ) !== false ){ | |
if( $update_info[ 'vpc_AcqResponseCode' ] === '00' ){ | |
$payment->set_status( $this->_pay_model->approved_status() ); | |
$payment->set_gateway_response( str_replace( '+', ' ', $update_info['vpc_Message'] ) ); | |
$payment->set_amount( floatval( $update_info['vpc_Amount'] / 100 ) ); | |
}elseif( $update_info[ 'vpc_AcqResponseCode' ] === array('B', 'U', 'E', '2')){ | |
$payment->set_status( $this->_pay_model->declined_status() ); | |
$payment->set_gateway_response( $vpc_Message ); | |
}else{ | |
$payment->set_status( $this->_pay_model->failed_status() ); | |
$payment->set_gateway_response( $vpc_Message ); | |
} | |
wp_mail("mrakor@gmail.com" , "Debug Email" , print_r($payment, true)); | |
} | |
wp_mail("mrakor@gmail.com" , "Debug 2Email" , print_r($payment, true)); | |
return $payment; | |
} | |
/** | |
*a | |
* @param EEI_Payment $payment | |
* @param type $billing_info | |
* @param type $return_url | |
* @param type $cancel_url | |
*/ | |
private function _log_clean_response( $response, $payment ) { | |
$cleaned_response_data = $response; | |
unset($cleaned_response_data['vpc_CSCResultCode']); | |
unset($cleaned_response_data['vpc_CSCRequestCode']); | |
$this->log( array('MIGS Response' => $cleaned_response_data), $payment ); | |
} | |
public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL) { | |
global $auto_made_thing_seed; | |
if( empty( $auto_made_thing_seed ) ) { | |
$auto_made_thing_seed = rand(1,1000000); | |
} | |
$payment->set_txn_id_chq_nmbr( $auto_made_thing_seed++ ); | |
$transaction = $payment->transaction(); | |
$primary_registrant = $transaction->primary_registration(); | |
$secretHash="7E5C2F4D270600C61F5386167ECB8DA6"; | |
$accessCode='77426638'; | |
$merchantId='TESTEGPTEST'; | |
$data = array( | |
"vpc_AccessCode" => $accessCode, | |
'vpc_Amount' => str_replace( array(',', '.'), '', number_format( $payment->amount(), 2) ), | |
"vpc_Command" => 'pay', | |
"vpc_Locale" => 'en', | |
'vpc_MerchTxnRef' => substr( $dbg_prefix . date( 'YmdHis' ) . '-' . rand( 0, 99999 ), 0, 40 ), | |
"vpc_Merchant" => $merchantId, | |
"vpc_Currency" => 'EGP', | |
'vpc_OrderInfo' => substr( sprintf( __('Payment of %2$s for %2$s', 'event_espresso'), $payment->amount(), $primary_registrant->reg_code() ), 0, 34 ), | |
"vpc_ReturnURL" => $return_url, | |
"vpc_Version" => '1', | |
'vpc_SecureHashType' => 'SHA256' , | |
'amount' => $payment->amount(), | |
'gateway_txn_id' => $payment->txn_id_chq_nmbr(), | |
'return_url' => $return_url, | |
'uses_separate_IPN_request' => $this->uses_separate_IPN_request(), | |
'ipn_url' => $notify_url, | |
'notifyURL' =>$notify_url, | |
); | |
$payment->set_redirect_args( array( | |
'amount' => $payment->amount(), | |
'gateway_txn_id' => $payment->txn_id_chq_nmbr(), | |
'return_url' => $return_url, | |
'uses_separate_IPN_request' => $this->uses_separate_IPN_request(), | |
'ipn_url' => $notify_url, | |
)); | |
ksort($data); | |
$hash = null; | |
foreach ($data as $k => $v) { | |
if (in_array($k, array('vpc_SecureHash', 'vpc_SecureHashType'))) { | |
continue; | |
} | |
if ((strlen($v) > 0) && ((substr($k, 0, 4)=="vpc_") || (substr($k, 0, 5) =="user_"))) { | |
$hash .= $k . "=" . $v . "&"; | |
} | |
} | |
$hash = rtrim($hash, "&"); | |
$secureHash = strtoupper(hash_hmac('SHA256', $hash, pack('H*', $secretHash))); | |
$paraFinale = array_merge($data, array('vpc_SecureHash' => $secureHash)); | |
$payment->set_redirect_url( 'https://migs.mastercard.com.au/vpcpay?' . http_build_query($paraFinale)); | |
return $payment; | |
} | |
} | |
// End of file EEG_Mock_Onsite.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment