minor fixes

This commit is contained in:
David Bomba 2024-04-16 22:01:25 +10:00
parent c1075c174c
commit cacecbc086
4 changed files with 196 additions and 108 deletions

View File

@ -67,6 +67,7 @@ class EDocRules
"type" => "dropdown",
"resource" => "CondizioniPagamento",
"required" => false,
"children" => [],
],
[
"key" => "DatiContratto",
@ -74,6 +75,14 @@ class EDocRules
"type" => "object",
"resource" => "DatiContratto",
"required" => false,
"children" => [
[
"key"=> "RiferimentoNumeroLinea",
"validation" => [
"string","min:1","max:10","required"
],
]
],
],
[
"key" => "DatiOrdineAcquisto",

View File

@ -144,7 +144,6 @@ class TwilioController extends BaseController
public function generate2faResetCode(Generate2faRequest $request)
{
nlog($request->all());
nlog($request->headers());
$user = User::where('email', $request->email)->first();

View File

@ -167,9 +167,9 @@ class PayPalRestPaymentDriver extends BaseDriver
$data['currency'] = $this->client->currency()->code;
// return render('gateways.paypal.ppcp.card', $data);
return render('gateways.paypal.ppcp.card', $data);
return render('gateways.paypal.pay', $data);
// return render('gateways.paypal.pay', $data);
}
@ -327,6 +327,65 @@ return render('gateways.paypal.pay', $data);
}
private function getPaymentSource(): array
{
if($this->gateway_type_id == 1) {
return [
"card" => [
"attributes" => [
"verification" => [
"method" => "SCA_WHEN_REQUIRED", //SCA_ALWAYS
],
],
"name" => $this->client->present()->primary_contact_name(),
"email_address" => $this->client->present()->email(),
"address" => [
"address_line_1" => $this->client->address1,
"address_line_2" => $this->client->address2,
"admin_area_2" => $this->client->city,
"admin_area_1" => $this->client->state,
"postal_code" => $this->client->postal_code,
"country_code" => $this->client->country->iso_3166_2,
],
"experience_context" => [
"user_action" => "PAY_NOW"
],
"stored_credential" => [
"payment_initiator" => "MERCHANT", //"CUSTOMER" who initiated the transaction?
"payment_type" => "UNSCHEDULED",
"usage"=> "DERIVED",
],
],
];
}
return [
"paypal" => [
"name" => [
"given_name" => $this->client->present()->first_name(),
"surname" => $this->client->present()->last_name(),
],
"email_address" => $this->client->present()->email(),
"address" => [
"address_line_1" => $this->client->address1,
"address_line_2" => $this->client->address2,
"admin_area_2" => $this->client->city,
"admin_area_1" => $this->client->state,
"postal_code" => $this->client->postal_code,
"country_code" => $this->client->country->iso_3166_2,
],
"experience_context" => [
"user_action" => "PAY_NOW"
],
],
];
}
private function createOrder(array $data): string
{
@ -341,27 +400,7 @@ return render('gateways.paypal.pay', $data);
$order = [
"intent" => "CAPTURE",
"payment_source" => [
"paypal" => [
"name" => [
"given_name" => $this->client->present()->first_name(),
"surname" => $this->client->present()->last_name(),
],
"email_address" => $this->client->present()->email(),
"address" => [
"address_line_1" => $this->client->address1,
"address_line_2" => $this->client->address2,
"admin_area_2" => $this->client->city,
"admin_area_1" => $this->client->state,
"postal_code" => $this->client->postal_code,
"country_code" => $this->client->country->iso_3166_2,
],
"experience_context" => [
"user_action" => "PAY_NOW"
],
],
],
"payment_source" => $this->getPaymentSource(),
"purchase_units" => [
[
"custom_id" => $this->payment_hash->hash,

View File

@ -1,4 +1,4 @@
@extends('portal.ninja2020.layout.payments', ['gateway_title' => ctrans('texts.payment_type_credit_card'), 'card_title' => 'PayPal'])
@extends('portal.ninja2020.layout.payments', ['gateway_title' => ctrans('texts.payment_type_credit_card'), 'card_title' => ''])
@section('gateway_head')
@ -14,19 +14,23 @@
<input type="hidden" name="amount_with_fee" id="amount_with_fee" value="{{ $total['amount_with_fee'] }}"/>
</form>
<div class="alert alert-failure mb-4" hidden id="errors"></div>
<div class="alert alert-failure mb-4" hidden id="errors"></div>
<div id="paypal-button-container" class="paypal-button-container"></div>
<div id="checkout-form">
<!-- Containers for Card Fields hosted by PayPal -->
<div id="card-name-field-container"></div>
<!-- <div id="card-name-field-container"></div> -->
<div id="card-number-field-container"></div>
<div id="card-expiry-field-container"></div>
<div id="card-cvv-field-container"></div>
<button id="card-field-submit-button" type="button">
Pay now with Card Fields
</button>
<div class="expcvv" style="display:flex;">
<div id="card-expiry-field-container" style="width:50%"></div>
<div id="card-cvv-field-container" style="width:50%"></div>
</div>
<!-- <button id="card-field-submit-button" type="button">
{{ ctrans('texts.pay_now') }}
</button> -->
@include('portal.ninja2020.gateways.includes.pay_now')
</div>
@endsection
@ -34,17 +38,32 @@
@endsection
@push('footer')
<script src="https://www.paypal.com/sdk/js?client-id={!! $client_id !!}&components=card-fields&debug=true" data-partner-attribution-id="invoiceninja_SP_PPCP"></script>
<link rel="stylesheet" type="text/css" href=https://www.paypalobjects.com/webstatic/en_US/developer/docs/css/cardfields.css />
<script src="https://www.paypal.com/sdk/js?client-id={!! $client_id !!}&components=card-fields" data-partner-attribution-id="invoiceninja_SP_PPCP"></script>
<script>
const clientId = "{{ $client_id }}";
const orderId = "{!! $order_id !!}";
const cardStyle = {
'input': {
'font-size': '16px',
'font-family': 'courier, monospace',
'font-weight': 'lighter',
'color': '#ccc',
},
'.invalid': {
'color': 'purple',
},
'.expcvv': {
'display': 'grid',
'grid-template-columns': 'auto'
}
};
const cardField = paypal.CardFields({
// env: 'production',
// fundingSource: fundingSource,
// style: cardStyle,
client: clientId,
createOrder: function(data, actions) {
return orderId;
@ -56,86 +75,108 @@
return actions.restart();
}
document.getElementById("gateway_response").value =JSON.stringify( data );
document.getElementById("server_response").submit();
console.log("on approve");
console.log(data);
console.log(actions);
document.getElementById("gateway_response").value = JSON.stringify( data );
document.getElementById("server_response").submit();
},
onCancel: function() {
window.location.href = "/client/invoices/";
},
onError: function(error) {
document.getElementById("gateway_response").value = error;
document.getElementById("server_response").submit();
},
// onError: function(error) {
// document.getElementById('errors').textContent = `Sorry, your transaction could not be processed...\n\n${error.message}`;
// document.getElementById('errors').hidden = false;
// // document.getElementById("gateway_response").value = error;
// // document.getElementById("server_response").submit();
// },
onClick: function (){
// document.getElementById('paypal-button-container').hidden = true;
}
})
.render('#paypal-button-container');
// .render('#paypal-button-container').catch(function(err) {
// document.getElementById('errors').textContent = err;
// document.getElementById('errors').hidden = false;
// });
document.getElementById("server_response").addEventListener('submit', (e) => {
if (document.getElementById("server_response").classList.contains('is-submitting')) {
e.preventDefault();
}
document.getElementById("server_response").classList.add('is-submitting');
});
// Render each field after checking for eligibility
if (cardField.isEligible()) {
const nameField = cardField.NameField();
nameField.render("#card-name-field-container");
const numberField = cardField.NumberField();
numberField.render("#card-number-field-container");
const cvvField = cardField.CVVField();
cvvField.render("#card-cvv-field-container");
const expiryField = cardField.ExpiryField();
expiryField.render("#card-expiry-field-container");
// Add click listener to submit button and call the submit function on the CardField component
document
.getElementById("card-field-submit-button")
.addEventListener("click", () => {
cardField.submit({
// From your billing address fields
billingAddress: {
addressLine1: document.getElementById(
"card-billing-address-line-1",
).value,
addressLine2: document.getElementById(
"card-billing-address-line-2",
).value,
adminArea1: document.getElementById(
"card-billing-address-admin-area-line-1",
).value,
adminArea2: document.getElementById(
"card-billing-address-admin-area-line-2",
).value,
countryCode: document.getElementById(
"card-billing-address-country-code",
).value,
postalCode: document.getElementById(
"card-billing-address-postal-code",
).value,
}
}).then(() => {
// submit successful
});
});
}
else {
console.log("i must not be eligible?");
}
// Render each field after checking for eligibility
if (cardField.isEligible()) {
const numberField = cardField.NumberField({
inputEvents: {
onChange: (event)=> {
console.log("returns a stateObject", event);
}
},
});
numberField.render("#card-number-field-container");
const cvvField = cardField.CVVField({
inputEvents: {
onChange: (event)=> {
console.log("returns a stateObject", event);
}
},
});
cvvField.render("#card-cvv-field-container");
const expiryField = cardField.ExpiryField({
inputEvents: {
onChange: (event)=> {
console.log("returns a stateObject", event);
}
},
});
expiryField.render("#card-expiry-field-container");
document.getElementById("pay-now").addEventListener('click', (e) => {
document.getElementById('errors').textContent = '';
document.getElementById('errors').hidden = true;
document.getElementById('pay-now').disabled = true;
document.querySelector('#pay-now > svg').classList.remove('hidden');
document.querySelector('#pay-now > svg').classList.add('justify-center');
document.querySelector('#pay-now > span').classList.add('hidden');
cardField.submit().then((response) => {
console.log("then");
console.log(response);
// lets goooo
}).catch((error) => {
console.log(error);
document.getElementById('pay-now').disabled = false;
document.querySelector('#pay-now > svg').classList.add('hidden');
document.querySelector('#pay-now > span').classList.remove('hidden');
if(error.message == 'INVALID_NUMBER'){
document.getElementById('errors').textContent = "{{ ctrans('texts.invalid_card_number') }}";
}
else if(error.message == 'INVALID_CVV') {
document.getElementById('errors').textContent = "{{ ctrans('texts.invalid_cvv') }}";
}
else if(error.message == 'INVALID_EXPIRY') {
document.getElementById('errors').textContent = "{{ ctrans('texts.invalid_cvv') }}";
}
document.getElementById('errors').hidden = false;
});
});
}
else {
}
</script>