1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Square SCA

This commit is contained in:
David Bomba 2021-10-03 14:50:01 +11:00
parent f0b51b7949
commit a321134e69
6 changed files with 68 additions and 3 deletions

View File

@ -41,6 +41,16 @@ class ClientPresenter extends EntityPresenter
return $contact_name;
}
public function first_name()
{
return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->first_name : $this->entity->contacts()->first()->first_name;
}
public function last_name()
{
return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->last_name : $this->entity->contacts()->first()->last_name;
}
public function primary_contact_name()
{
return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->first_name.' '.$this->entity->primary_contact->first()->last_name : 'No primary contact set';

View File

@ -124,11 +124,29 @@ class CreditCard
public function paymentView($data)
{
$data['gateway'] = $this->square_driver;
$data['amount'] = $this->square_driver->payment_hash->data->amount_with_fee;
$data['currencyCode'] = $this->square_driver->client->getCurrencyCode();
$data['contact'] = $this->buildClientObject();
return render('gateways.square.credit_card.pay', $data);
}
private function buildClientObject()
{
$client = new \stdClass;
$client->addressLines = [ $this->square_driver->client->address1, $this->square_driver->client->address2 ];
$client->givenName = $this->square_driver->client->present()->first_name();
$client->familyName = $this->square_driver->client->present()->last_name();
$client->email = $this->square_driver->client->present()->email;
$client->phone = $this->square_driver->client->phone;
$client->city = $this->square_driver->client->city;
$client->region = $this->square_driver->client->state;
$client->country = $this->square_driver->client->country->iso_3166_2;
return $client;
}
public function paymentResponse(PaymentResponseRequest $request)
{
$token = $request->sourceId;
@ -152,6 +170,9 @@ class CreditCard
$body->setLocationId($this->square_driver->company_gateway->getConfigField('locationId'));
$body->setReferenceId(Str::random(16));
if($request->has('verificationToken') && $request->input('verificationToken'))
$body->setVerificationToken($request->input('verificationToken'));
if ($request->shouldUseToken()) {
$body->setCustomerId($cgt->gateway_customer_reference);
}

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,7 @@
"/js/clients/payments/eway-credit-card.js": "/js/clients/payments/eway-credit-card.js?id=08ea84e9451abd434cff",
"/js/clients/payments/mollie-credit-card.js": "/js/clients/payments/mollie-credit-card.js?id=73b66e88e2daabcd6549",
"/js/clients/payments/paytrace-credit-card.js": "/js/clients/payments/paytrace-credit-card.js?id=c2b5f7831e1a46dd5fb2",
"/js/clients/payments/square-credit-card.js": "/js/clients/payments/square-credit-card.js?id=994c79534ee0a7391f69",
"/js/clients/payments/square-credit-card.js": "/js/clients/payments/square-credit-card.js?id=24de1e73937c39b68f3f",
"/js/clients/payments/stripe-ach.js": "/js/clients/payments/stripe-ach.js?id=81c2623fc1e5769b51c7",
"/js/clients/payments/stripe-alipay.js": "/js/clients/payments/stripe-alipay.js?id=665ddf663500767f1a17",
"/js/clients/payments/stripe-credit-card.js": "/js/clients/payments/stripe-credit-card.js?id=a30464874dee84678344",

View File

@ -49,6 +49,18 @@ class SquareCreditCard {
let result = await this.card.tokenize();
/* SCA */
let verificationToken;
verificationToken = await verifyBuyer(
this.payments,
result.token
);
console.debug('Verification Token:', verificationToken);
document.querySelector('input[name="verificationToken"]').value =
verificationToken;
if (result.status === 'OK') {
document.getElementById('sourceId').value = result.token;
@ -77,6 +89,22 @@ class SquareCreditCard {
return document.getElementById('server_response').submit();
}
/* SCA */
async verifyBuyer(payments, token) {
const verificationDetails = {
amount: document.querySelector('meta[name=amount]').content,
billingContact: document.querySelector('meta[name=contact]').content,
currencyCode: document.querySelector('meta[name=currencyCode]').content,
intent: 'CHARGE'
};
const verificationResults = await payments.verifyBuyer(
token,
verificationDetails
);
return verificationResults.token;
}
async handle() {
await this.init();

View File

@ -4,6 +4,11 @@
@section('gateway_head')
<meta name="square-appId" content="{{ $gateway->company_gateway->getConfigField('applicationId') }}">
<meta name="square-locationId" content="{{ $gateway->company_gateway->getConfigField('locationId') }}">
<meta name="contact" content="{{ $contact }}">
<meta name="amount" content="{{ $amount }}">
<meta name="contact" content="{{ $contact }}">
<meta name="currencyCode" content="{{ $currencyCode }}">
@endsection
@section('gateway_content')
@ -17,6 +22,7 @@
<input type="hidden" name="token">
<input type="hidden" name="sourceId" id="sourceId">
<input type="hidden" name="verificationToken" id="verificationToken">
</form>
<div class="alert alert-failure mb-4" hidden id="errors"></div>