Turning on token billing for PayFast

This commit is contained in:
David Bomba 2021-09-23 13:26:50 +10:00
parent d2735df1c3
commit e08daf23fc

View File

@ -79,26 +79,17 @@ class Token
$header =[ $header =[
'merchant-id' => $this->payfast->company_gateway->getConfigField('merchantId'), 'merchant-id' => $this->payfast->company_gateway->getConfigField('merchantId'),
'version' => 'v1',
'timestamp' => now()->format('c'), 'timestamp' => now()->format('c'),
'version' => 'v1',
]; ];
$body = [ $body['body'] = [
'merchant_id' => $this->payfast->company_gateway->getConfigField('merchantId'),
'merchant_key' => $this->payfast->company_gateway->getConfigField('merchantKey'),
'return_url' => route('client.payment_methods.index'),
'cancel_url' => route('client.payment_methods.index'),
'notify_url' => $this->payfast->genericWebhookUrl(),
'm_payment_id' => $payment_hash->hash,
'amount' => $amount, 'amount' => $amount,
'item_name' => 'purchase', 'item_name' => 'purchase',
'item_description' => 'Purchase', 'item_description' => 'Purchase',
'subscription_type' => 1,
'passphrase' => $this->payfast->company_gateway->getConfigField('passphrase'),
]; ];
$header['signature'] = $this->payfast->generateSignature($body); $header['signature'] = $this->generate_parameter_string(array_merge($header, $body));
//$header['signature'] = $this->genSig($body); //$header['signature'] = $this->genSig($body);
nlog($this->payfast->company_gateway->getConfigField('merchantId')); nlog($this->payfast->company_gateway->getConfigField('merchantId'));
@ -147,6 +138,43 @@ class Token
// } // }
} }
protected function generate_parameter_string( $api_data, $sort_data_before_merge = true, $skip_empty_values = true ) {
// if sorting is required the passphrase should be added in before sort.
if ( ! empty( $this->pass_phrase ) && $sort_data_before_merge ) {
$api_data['passphrase'] = $this->payfast->company_gateway->getConfigField('passPhrase');
}
if ( $sort_data_before_merge ) {
ksort( $api_data );
}
// concatenate the array key value pairs.
$parameter_string = '';
foreach ( $api_data as $key => $val ) {
if ( $skip_empty_values && empty( $val ) ) {
continue;
}
if ( 'signature' !== $key ) {
$val = urlencode( $val );
$parameter_string .= "$key=$val&";
}
}
// when not sorting passphrase should be added to the end before md5
if ( $sort_data_before_merge ) {
$parameter_string = rtrim( $parameter_string, '&' );
} elseif ( ! empty( $this->pass_phrase ) ) {
$parameter_string .= 'passphrase=' . urlencode( $this->pass_phrase );
} else {
$parameter_string = rtrim( $parameter_string, '&' );
}
return $parameter_string;
}
private function genSig($data) private function genSig($data)
{ {
$fields = []; $fields = [];