Square payments

This commit is contained in:
= 2021-08-14 19:32:16 +10:00
parent 86e8533e59
commit 77c072fd10
6 changed files with 94 additions and 9 deletions

View File

@ -787,6 +787,27 @@ class CreateSingleAccount extends Command
$cg->fees_and_limits = $fees_and_limits; $cg->fees_and_limits = $fees_and_limits;
$cg->save(); $cg->save();
} }
if (config('ninja.testvars.square') && ($this->gateway == 'all' || $this->gateway == 'square')) {
$cg = new CompanyGateway;
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '65faab2ab6e3223dbe848b1686490baz';
$cg->require_cvv = true;
$cg->require_billing_address = true;
$cg->require_shipping_address = true;
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.square'));
$cg->save();
$gateway_types = $cg->driver(new Client)->gatewayTypes();
$fees_and_limits = new stdClass;
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
} }
private function createRecurringInvoice($client) private function createRecurringInvoice($client)

View File

@ -81,9 +81,13 @@ class Gateway extends StaticModel
case 1: case 1:
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]];//Authorize.net return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]];//Authorize.net
break; break;
case 1: case 11:
return [GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => false]];//Payfast return [GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => false]];//Payfast
break; break;
case 7:
return [
GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true], // Mollie
];
case 15: case 15:
return [GatewayType::PAYPAL => ['refund' => true, 'token_billing' => false]]; //Paypal return [GatewayType::PAYPAL => ['refund' => true, 'token_billing' => false]]; //Paypal
break; break;
@ -110,11 +114,12 @@ class Gateway extends StaticModel
GatewayType::PAYPAL => ['refund' => true, 'token_billing' => true] GatewayType::PAYPAL => ['refund' => true, 'token_billing' => true]
]; ];
break; break;
case 7: case 57:
return [ return [
GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true], // Mollie GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true], //Square
]; ];
break; break;
break;
default: default:
return []; return [];
break; break;

View File

@ -30,22 +30,22 @@ class SquarePaymentDriver extends BaseDriver
public $can_authorise_credit_card = true; //does this gateway support authorizations? public $can_authorise_credit_card = true; //does this gateway support authorizations?
public $square; //initialized gateway public $square;
public $payment_method; //initialized payment method public $payment_method;
public static $methods = [ public static $methods = [
GatewayType::CREDIT_CARD => CreditCard::class, //maps GatewayType => Implementation class GatewayType::CREDIT_CARD => CreditCard::class, //maps GatewayType => Implementation class
]; ];
const SYSTEM_LOG_TYPE = SystemLog::TYPE_SQUARE; //define a constant for your gateway ie TYPE_YOUR_CUSTOM_GATEWAY - set the const in the SystemLog model const SYSTEM_LOG_TYPE = SystemLog::TYPE_SQUARE;
public function init() public function init()
{ {
$this->square = new Square\SquareClient([ $this->square = new Square\SquareClient([
'accessToken' => 'EAAAEHeoSxEUZWXCd0makP0-HA0V4OLZ-S-T2Gmc91llp08ColiOX9NpP-LQZIId', 'accessToken' => $this->company_gateway->getConfigField('accessToken'),
'environment' => Square\Environment::SANDBOX, 'environment' => $this->company_gateway->getConfigField('testMode') ? Square\Environment::SANDBOX : Square\Environment::PRODUCTION,
]); ]);
return $this; /* This is where you boot the gateway with your auth credentials*/ return $this; /* This is where you boot the gateway with your auth credentials*/

View File

@ -90,6 +90,7 @@ return [
'decrypted' => env('PAYTRACE_KEYS', ''), 'decrypted' => env('PAYTRACE_KEYS', ''),
], ],
'mollie' => env('MOLLIE_KEYS', ''), 'mollie' => env('MOLLIE_KEYS', ''),
'square' => env('SQUARE_KEYS',''),
], ],
'contact' => [ 'contact' => [
'email' => env('MAIL_FROM_ADDRESS'), 'email' => env('MAIL_FROM_ADDRESS'),

View File

@ -80,6 +80,7 @@ class PaymentLibrariesSeeder extends Seeder
['id' => 53, 'name' => 'PagSeguro', 'provider' => 'PagSeguro', 'key' => 'ef498756b54db63c143af0ec433da803', 'fields' => '{"email":"","token":"","sandbox":false}'], ['id' => 53, 'name' => 'PagSeguro', 'provider' => 'PagSeguro', 'key' => 'ef498756b54db63c143af0ec433da803', 'fields' => '{"email":"","token":"","sandbox":false}'],
['id' => 54, 'name' => 'PAYMILL', 'provider' => 'Paymill', 'key' => 'ca52f618a39367a4c944098ebf977e1c', 'fields' => '{"apiKey":""}'], ['id' => 54, 'name' => 'PAYMILL', 'provider' => 'Paymill', 'key' => 'ca52f618a39367a4c944098ebf977e1c', 'fields' => '{"apiKey":""}'],
['id' => 55, 'name' => 'Custom', 'provider' => 'Custom', 'is_offsite' => true, 'sort_order' => 21, 'key' => '54faab2ab6e3223dbe848b1686490baa', 'fields' => '{"name":"","text":""}'], ['id' => 55, 'name' => 'Custom', 'provider' => 'Custom', 'is_offsite' => true, 'sort_order' => 21, 'key' => '54faab2ab6e3223dbe848b1686490baa', 'fields' => '{"name":"","text":""}'],
['id' => 57, 'name' => 'Square', 'provider' => 'Square', 'is_offsite' => false, 'sort_order' => 21, 'key' => '65faab2ab6e3223dbe848b1686490baz', 'fields' => '{"accessToken":"","applicationId":"","locationId":"","testMode":"false"}'],
]; ];
foreach ($gateways as $gateway) { foreach ($gateways as $gateway) {
@ -96,7 +97,7 @@ class PaymentLibrariesSeeder extends Seeder
Gateway::query()->update(['visible' => 0]); Gateway::query()->update(['visible' => 0]);
Gateway::whereIn('id', [1,7,15,20,39,46,55,50])->update(['visible' => 1]); Gateway::whereIn('id', [1,7,15,20,39,46,55,50,57])->update(['visible' => 1]);
if (Ninja::isHosted()) { if (Ninja::isHosted()) {
Gateway::whereIn('id', [20])->update(['visible' => 0]); Gateway::whereIn('id', [20])->update(['visible' => 0]);

View File

@ -0,0 +1,57 @@
@extends('portal.ninja2020.layout.payments', ['gateway_title' => ctrans('texts.payment_type_credit_card'), 'card_title'
=> ctrans('texts.payment_type_credit_card')])
@section('gateway_head')
@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="txt" id=HPF_Token name= HPF_Token hidden>
<input type="txt" id=enc_key name= enc_key hidden>
<input type="text" name="token" hidden>
<div class="alert alert-failure mb-4" hidden id="errors"></div>
@component('portal.ninja2020.components.general.card-element-single')
<div id="card-container"></div>
<button id="card-button" type="button">Add</button>
<div id="payment-status-container"></div>
</form>
@endcomponent
@endsection
@section('gateway_footer')
<script type="text/javascript" src="https://sandbox.web.squarecdn.com/v1/square.js"></script>.
<script>
const appId = "{{ $gateway->company_gateway->getConfigField('applicationId') }}";
const locationId = "{{ $gateway->company_gateway->getConfigField('locationId') }}";
async function initializeCard(payments) {
const card = await payments.card();
await card.attach('#card-container');
return card;
}
document.addEventListener('DOMContentLoaded', async function () {
if (!window.Square) {
throw new Error('Square.js failed to load properly');
}
const payments = window.Square.payments(appId, locationId);
let card;
try {
card = await initializeCard(payments);
} catch (e) {
console.error('Initializing Card failed', e);
return;
}
// Step 5.2: create card payment
});
</script>
@endsection