This commit is contained in:
David Bomba 2021-06-24 15:46:10 +10:00
parent 50749cd2bb
commit 15bdb3ff3c
4 changed files with 125 additions and 33 deletions

View File

@ -358,6 +358,11 @@ class CompanyGateway extends BaseModel
return $fee;
}
public function webhookUrl()
{
return route('payment_webhook', ['company_key' => $this->company->company_key, 'company_gateway_id' => $this->hashed_id]);
}
/**
* we need to average out the gateway fees across all the invoices
* so lets iterate.
@ -399,4 +404,6 @@ class CompanyGateway extends BaseModel
return $this
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
}
}

View File

@ -32,11 +32,71 @@ class CreditCard
$this->payfast = $payfast;
}
/*
$data = array();
$data['merchant_id'] = $this->getMerchantId();
$data['merchant_key'] = $this->getMerchantKey();
$data['return_url'] = $this->getReturnUrl();
$data['cancel_url'] = $this->getCancelUrl();
$data['notify_url'] = $this->getNotifyUrl();
if ($this->getCard()) {
$data['name_first'] = $this->getCard()->getFirstName();
$data['name_last'] = $this->getCard()->getLastName();
$data['email_address'] = $this->getCard()->getEmail();
}
$data['m_payment_id'] = $this->getTransactionId();
$data['amount'] = $this->getAmount();
$data['item_name'] = $this->getDescription();
$data['custom_int1'] = $this->getCustomInt1();
$data['custom_int2'] = $this->getCustomInt2();
$data['custom_int3'] = $this->getCustomInt3();
$data['custom_int4'] = $this->getCustomInt4();
$data['custom_int5'] = $this->getCustomInt5();
$data['custom_str1'] = $this->getCustomStr1();
$data['custom_str2'] = $this->getCustomStr2();
$data['custom_str3'] = $this->getCustomStr3();
$data['custom_str4'] = $this->getCustomStr4();
$data['custom_str5'] = $this->getCustomStr5();
if ($this->getPaymentMethod()) {
$data['payment_method'] = $this->getPaymentMethod();
}
if (1 == $this->getSubscriptionType()) {
$data['subscription_type'] = $this->getSubscriptionType();
$data['billing_date'] = $this->getBillingDate();
$data['recurring_amount'] = $this->getRecurringAmount();
$data['frequency'] = $this->getFrequency();
$data['cycles'] = $this->getCycles();
}
if (2 == $this->getSubscriptionType()) {
$data['subscription_type'] = $this->getSubscriptionType();
}
$data['passphrase'] = $this->getParameter('passphrase'); 123456789012aV
$data['signature'] = $this->generateSignature($data);
*/
public function authorizeView($data)
{
// $data['gateway'] = $this->wepay_payment_driver;
// return render('gateways.wepay.authorize.authorize', $data);
$data = [
'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->company_gateway->webhookUrl(),
'amount' => 0,
'item_name' => 'pre-auth',
'subscription_type' => 2,
'passphrase' => $this->payfast->company_gateway->getConfigField('passphrase'),
];
$data['signature'] = $this->payfast->generateSignature($data);
$data['gateway'] = $this->payfast;
return render('gateways.payfast.authorize', $data);
}
public function authorizeResponse($request)

View File

@ -18,6 +18,7 @@ use App\Models\PaymentHash;
use App\Models\SystemLog;
use App\PaymentDrivers\PayFast\CreditCard;
use App\Utils\Traits\MakesHash;
use \PayFastPayment;
class PayFastPaymentDriver extends BaseDriver
{
@ -39,17 +40,33 @@ class PayFastPaymentDriver extends BaseDriver
const SYSTEM_LOG_TYPE = SystemLog::TYPE_PAYFAST;
//Live: https://www.payfast.co.za/eng/process
//Sandbox: https://sandbox.payfast.co.za/eng/process
public function gatewayTypes(): array
{
$types = [];
$types[] = GatewayType::CREDIT_CARD;
return $types;
}
public function init()
{
$this->payfast = new PayFastPayment(
[
'merchantId' => $this->company_gateway->getConfigField('merchantId'),
'merchantKey' => $this->company_gateway->getConfigField('merchantKey'),
'passPhrase' => $this->company_gateway->getConfigField('passPhrase'),
'testMode' => $this->company_gateway->getConfigField('testMode')
]
);
try{
$this->payfast = new PayFastPayment(
[
'merchantId' => $this->company_gateway->getConfigField('merchantId'),
'merchantKey' => $this->company_gateway->getConfigField('merchantKey'),
'passPhrase' => $this->company_gateway->getConfigField('passPhrase'),
'testMode' => $this->company_gateway->getConfigField('testMode')
]
);
} catch(Exception $e) {
echo 'There was an exception: '.$e->getMessage();
}
return $this;
}
@ -90,4 +107,21 @@ class PayFastPaymentDriver extends BaseDriver
{
return $this->payment_method->yourTokenBillingImplmentation(); //this is your custom implementation from here
}
public function generateSignature($data, $passPhrase = null)
{
// Create parameter string
$pfOutput = '';
foreach( $data as $key => $val ) {
if($val !== '') {
$pfOutput .= $key .'='. urlencode( trim( $val ) ) .'&';
}
}
// Remove last ampersand
$getString = substr( $pfOutput, 0, -1 );
if( $passPhrase !== null ) {
$getString .= '&passphrase='. urlencode( trim( $passPhrase ) );
}
return md5( $getString );
}
}

View File

@ -1,32 +1,25 @@
@extends('portal.ninja2020.layout.payments', ['gateway_title' => ctrans('texts.credit_card'), 'card_title' => ctrans('texts.credit_card')])
@section('gateway_head')
<meta name="wepay-environment" content="{{ config('ninja.wepay.environment') }}">
<meta name="wepay-action" content="authorize">
<meta name="wepay-client-id" content="{{ config('ninja.wepay.client_id') }}">
<meta name="contact-email" content="{{ $contact->email }}">
<meta name="client-postal-code" content="{{ $contact->client->postal_code }}">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="{{ asset('js/clients/payments/card-js.min.js') }}"></script>
<link href="{{ asset('css/card-js.min.css') }}" rel="stylesheet" type="text/css">
<script type="text/javascript" src="https://static.wepay.com/min/js/tokenization.4.latest.js"></script>
@endsection
@section('gateway_content')
<form action="{{ route('client.payment_methods.store', ['method' => App\Models\GatewayType::CREDIT_CARD]) }}"
method="post" id="server_response">
@csrf
<form action="https://sandbox.payfast.co.za/eng/process" method="post">
<input type="hidden" name="merchant_id" value="{{ $merchant_id }}">
<input type="hidden" name="merchant_key" value="{{ $merchant_key }}">
<input type="hidden" name="return_url" value="{{ $return_url }}">
<input type="hidden" name="cancel_url" value="{{ $cancel_url }}">
<input type="hidden" name="notify_url" value="{{ $notify_url }}">
<input type="hidden" name="amount" value="{{ $amount }}">
<input type="hidden" name="item_name" value="{{ $item_name }}">
<input type="hidden" name="subscription_type" value="{{ $subscription_type }}">
<input type="hidden" name="passphrase" value="{{ $passphrase }}">
<input type="hidden" name="signature" value="{{ $signature }}">
<input type="hidden" name="company_gateway_id" value="{{ $gateway->company_gateway->id }}">
<input type="hidden" name="payment_method_id" value="1">
<input type="hidden" name="gateway_response" id="gateway_response">
<input type="hidden" name="is_default" id="is_default">
<input type="hidden" name="credit_card_id" id="credit_card_id">
</form>
<input type="submit">
</form>
@if(!Request::isSecure())
<p class="alert alert-failure">{{ ctrans('texts.https_required') }}</p>
@ -38,8 +31,6 @@
{{ ctrans('texts.credit_card') }}
@endcomponent
@include('portal.ninja2020.gateways.wepay.includes.credit_card')
@component('portal.ninja2020.gateways.includes.pay_now', ['id' => 'card_button'])
{{ ctrans('texts.add_payment_method') }}
@endcomponent