1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00
This commit is contained in:
David Bomba 2021-06-24 14:43:14 +10:00
parent 6e212d7d55
commit 50749cd2bb
6 changed files with 249 additions and 1 deletions

View File

@ -67,6 +67,7 @@ class SystemLog extends Model
const TYPE_CUSTOM = 306;
const TYPE_BRAINTREE = 307;
const TYPE_WEPAY = 309;
const TYPE_PAYFAST = 310;
const TYPE_QUOTA_EXCEEDED = 400;

View File

@ -0,0 +1,52 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\PaymentDrivers\PayFast;
use App\Exceptions\PaymentFailed;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\PayFastPaymentDriver;
use Illuminate\Support\Str;
class CreditCard
{
public $payfast;
public function __construct(PayFastPaymentDriver $payfast)
{
$this->payfast = $payfast;
}
public function authorizeView($data)
{
// $data['gateway'] = $this->wepay_payment_driver;
// return render('gateways.wepay.authorize.authorize', $data);
}
public function authorizeResponse($request)
{
}
}

View File

@ -0,0 +1,93 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\PaymentDrivers;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\SystemLog;
use App\PaymentDrivers\PayFast\CreditCard;
use App\Utils\Traits\MakesHash;
class PayFastPaymentDriver extends BaseDriver
{
use MakesHash;
public $refundable = true; //does this gateway support refunds?
public $token_billing = true; //does this gateway support token billing?
public $can_authorise_credit_card = true; //does this gateway support authorizations?
public $payfast; //initialized gateway
public $payment_method; //initialized payment method
public static $methods = [
GatewayType::CREDIT_CARD => CreditCard::class,
];
const SYSTEM_LOG_TYPE = SystemLog::TYPE_PAYFAST;
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')
]
);
return $this;
}
public function setPaymentMethod($payment_method_id)
{
$class = self::$methods[$payment_method_id];
$this->payment_method = new $class($this);
return $this;
}
public function authorizeView(array $data)
{
return $this->payment_method->authorizeView($data); //this is your custom implementation from here
}
public function authorizeResponse($request)
{
return $this->payment_method->authorizeResponse($request); //this is your custom implementation from here
}
public function processPaymentView(array $data)
{
return $this->payment_method->paymentView($data); //this is your custom implementation from here
}
public function processPaymentResponse($request)
{
return $this->payment_method->paymentResponse($request); //this is your custom implementation from here
}
public function refund(Payment $payment, $amount, $return_client_response = false)
{
return $this->payment_method->yourRefundImplementationHere(); //this is your custom implementation from here
}
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
return $this->payment_method->yourTokenBillingImplmentation(); //this is your custom implementation from here
}
}

View File

@ -63,6 +63,7 @@
"maennchen/zipstream-php": "^1.2",
"nwidart/laravel-modules": "^8.0",
"omnipay/paypal": "^3.0",
"payfast/payfast-php-sdk": "^1.1",
"pragmarx/google2fa": "^8.0",
"predis/predis": "^1.1",
"sentry/sentry-laravel": "^2",

53
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "013b0357f14c1782315168bc42234b34",
"content-hash": "cadeb954feac99fb76194b0ded979cab",
"packages": [
{
"name": "asm/php-ansible",
@ -5213,6 +5213,57 @@
},
"time": "2020-10-15T08:29:30+00:00"
},
{
"name": "payfast/payfast-php-sdk",
"version": "v1.1.2",
"source": {
"type": "git",
"url": "https://github.com/PayFast/payfast-php-sdk.git",
"reference": "1372980e38f381b84eed7eb46a40d5819a4fe58c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PayFast/payfast-php-sdk/zipball/1372980e38f381b84eed7eb46a40d5819a4fe58c",
"reference": "1372980e38f381b84eed7eb46a40d5819a4fe58c",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/guzzle": ">=6.0.0",
"php": ">=7.2.5"
},
"require-dev": {
"phpunit/phpunit": "^9"
},
"type": "library",
"autoload": {
"psr-4": {
"PayFast\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Claire Grant",
"email": "claire.grant@payfast.co.za"
}
],
"description": "PayFast PHP Library",
"keywords": [
"api",
"onsite",
"payfast",
"php"
],
"support": {
"issues": "https://github.com/PayFast/payfast-php-sdk/issues",
"source": "https://github.com/PayFast/payfast-php-sdk/tree/v1.1.2"
},
"time": "2021-03-15T19:58:26+00:00"
},
{
"name": "php-http/client-common",
"version": "2.3.0",

View File

@ -0,0 +1,50 @@
@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
<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>
@if(!Request::isSecure())
<p class="alert alert-failure">{{ ctrans('texts.https_required') }}</p>
@endif
<div class="alert alert-failure mb-4" hidden id="errors"></div>
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.method')])
{{ 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
@endsection
@section('gateway_footer')
@endsection