Working on authorization

This commit is contained in:
David Bomba 2021-06-11 18:30:39 +10:00
parent f268b7adcb
commit a441b3f79e
4 changed files with 189 additions and 13 deletions

View File

@ -0,0 +1,31 @@
<?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://opensource.org/licenses/AAL
*/
namespace App\PaymentDrivers\WePay;
use App\PaymentDrivers\WePayPaymentDriver;
class ACH
{
public $wepay;
public function __construct(WePayPaymentDriver $wepay)
{
$this->wepay = $wepay;
}
public function authorizeView($data)
{
}
}

View File

@ -25,7 +25,22 @@ class CreditCard
public function authorizeView($data)
{
return render('gateways.wepay.authorize.authorize', $data);
}
public function authorizeResponse($data)
{
//https://developer.wepay.com/api/api-calls/credit_card#authorize
// authorize the credit card
$response = $this->wepay->request('credit_card/authorize', array(
'client_id' => $account_id,
'client_secret' => 'A vacation home rental',
'credit_card_id' => 'goods',
));
// display the response
print_r($response);
}
}

View File

@ -16,6 +16,7 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\SystemLog;
use App\PaymentDrivers\WePay\ACH;
use App\PaymentDrivers\WePay\CreditCard;
use App\PaymentDrivers\WePay\Setup;
use App\Utils\Traits\MakesHash;
@ -26,18 +27,25 @@ class WePayPaymentDriver extends BaseDriver
{
use MakesHash;
public $refundable = true; //does this gateway support refunds?
/* Does this gateway support refunds? */
public $refundable = true;
public $token_billing = true; //does this gateway support token billing?
/* Does this gateway support token billing? */
public $token_billing = true;
public $can_authorise_credit_card = true; //does this gateway support authorizations?
/* Does this gateway support authorizations? */
public $can_authorise_credit_card = true;
public $wepay; //initialized gateway
/* Initialized gateway */
public $wepay;
public $payment_method; //initialized payment method
/* Initialized payment method */
public $payment_method;
/* Maps the Payment Gateway Type - to its implementation */
public static $methods = [
GatewayType::CREDIT_CARD => CreditCard::class, //maps GatewayType => Implementation class
GatewayType::CREDIT_CARD => CreditCard::class,
GatewayType::BANK_TRANSFER => ACH::class,
];
const SYSTEM_LOG_TYPE = SystemLog::TYPE_WEPAY;
@ -63,16 +71,40 @@ class WePayPaymentDriver extends BaseDriver
}
/**
* Return the gateway types that have been enabled
*
* @return array
*/
public function gatewayTypes(): array
{
$types = [];
if($this->company_gateway->fees_and_limits->{GatewayType::BANK_TRANSFER}->is_enabled)
$types[] = GatewayType::CREDIT_CARD;
if($this->company_gateway->fees_and_limits->{GatewayType::BANK_TRANSFER}->is_enabled)
$types[] = GatewayType::BANK_TRANSFER;
return $types;
}
/**
* Setup the gateway
*
* @param array $data user_id + company
* @return view
*/
public function setup(array $data)
{
return (new Setup($this))->boot($data);
}
public function processSetup(Request $request)
{
return (new Setup($this))->processSignup($request);
}
/**
* Set the payment method
*
* @param int $payment_method_id Alias of GatewayType
*/
public function setPaymentMethod($payment_method_id)
{
$class = self::$methods[$payment_method_id];

View File

@ -0,0 +1,98 @@
@extends('portal.ninja2020.layout.payments', ['gateway_title' => ctrans('texts.credit_card'), 'card_title' => ctrans('texts.credit_card')])
@section('gateway_head')
<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">
@endsection
@section('gateway_content')
<table>
<tr>
<td>Name: </td>
<td><input id="name" type="text"></td>
</tr>
<tr>
<td>Email: </td>
<td><input id="email" type="text"></td>
</tr>
<tr>
<td>Credit Card Number: </td>
<td><input id="cc-number" type="text"></td>
</tr>
<tr>
<td>Expiration Month: </td>
<td><input id="cc-month" type="text"></td>
</tr>
<tr>
<td>Expiration Year: </td>
<td><input id="cc-year" type="text"></td>
</tr>
<tr>
<td>CVV: </td>
<td><input id="cc-cvv" type="text"></td>
</tr>
<tr>
<td>Postal Code: </td>
<td><input id="postal_code" type="text"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Submit" id="cc-submit"></td>
</tr>
</table>
@endsection
@section('gateway_footer')
<script type="text/javascript" src="https://static.wepay.com/min/js/tokenization.4.latest.js"></script>
<script type="text/javascript">
(function() {
WePay.set_endpoint("stage"); // change to "production" when live
// Shortcuts
var d = document;
d.id = d.getElementById,
valueById = function(id) {
return d.id(id).value;
};
// For those not using DOM libraries
var addEvent = function(e,v,f) {
if (!!window.attachEvent) { e.attachEvent('on' + v, f); }
else { e.addEventListener(v, f, false); }
};
// Attach the event to the DOM
addEvent(d.id('cc-submit'), 'click', function() {
var userName = [valueById('name')].join(' ');
response = WePay.credit_card.create({
"client_id": 118711,
"user_name": valueById('name'),
"email": valueById('email'),
"cc_number": valueById('cc-number'),
"cvv": valueById('cc-cvv'),
"expiration_month": valueById('cc-month'),
"expiration_year": valueById('cc-year'),
"address": {
"postal_code": valueById('postal_code')
}
}, function(data) {
if (data.error) {
console.log(data);
// handle error response
} else {
// call your own app's API to save the token inside the data;
// show a success page
}
});
});
})();
</script>
@endsection