Clean up for paypal rest

This commit is contained in:
David Bomba 2024-04-26 21:17:15 +10:00
parent 399da26976
commit 990c75db60
3 changed files with 52 additions and 32 deletions

View File

@ -59,13 +59,13 @@ class EpcQrGenerator
<rect x='0' y='0' width='100%'' height='100%' />{$qr}</svg>"; <rect x='0' y='0' width='100%'' height='100%' />{$qr}</svg>";
} catch(\Throwable $e) { } catch(\Throwable $e) {
nlog("EPC QR failure => ".$e->getMessage()); // nlog("EPC QR failure => ".$e->getMessage());
return ''; return '';
} catch(\Exception $e) { } catch(\Exception $e) {
nlog("EPC QR failure => ".$e->getMessage()); // nlog("EPC QR failure => ".$e->getMessage());
return ''; return '';
} catch(InvalidArgumentException $e) { } catch(InvalidArgumentException $e) {
nlog("EPC QR failure => ".$e->getMessage()); // nlog("EPC QR failure => ".$e->getMessage());
return ''; return '';
} }

View File

@ -233,8 +233,8 @@ class PayPalPPCPPaymentDriver extends BaseDriver
/** /**
* Presents the Payment View to the client * Presents the Payment View to the client
* *
* @param mixed $data * @param array $data
* @return void * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/ */
public function processPaymentView($data) public function processPaymentView($data)
{ {
@ -251,7 +251,6 @@ class PayPalPPCPPaymentDriver extends BaseDriver
$data['gateway_type_id'] = $this->gateway_type_id; $data['gateway_type_id'] = $this->gateway_type_id;
$data['merchantId'] = $this->company_gateway->getConfigField('merchantId'); $data['merchantId'] = $this->company_gateway->getConfigField('merchantId');
$data['currency'] = $this->client->currency()->code; $data['currency'] = $this->client->currency()->code;
// nlog($data['merchantId']);
return render('gateways.paypal.ppcp.pay', $data); return render('gateways.paypal.ppcp.pay', $data);
@ -279,11 +278,11 @@ class PayPalPPCPPaymentDriver extends BaseDriver
"op" => "replace", "op" => "replace",
"path" => "/purchase_units/@reference_id=='default'/shipping/address", "path" => "/purchase_units/@reference_id=='default'/shipping/address",
"value" => [ "value" => [
"address_line_1" => strlen($this->client->shipping_address1) > 1 ? $this->client->shipping_address1 : $this->client->address1, "address_line_1" => strlen($this->client->shipping_address1 ?? '') > 1 ? $this->client->shipping_address1 : $this->client->address1,
"address_line_2" => $this->client->shipping_address2, "address_line_2" => $this->client->shipping_address2,
"admin_area_2" => strlen($this->client->shipping_city) > 1 ? $this->client->shipping_city : $this->client->city, "admin_area_2" => strlen($this->client->shipping_city ?? '') > 1 ? $this->client->shipping_city : $this->client->city,
"admin_area_1" => strlen($this->client->shipping_state) > 1 ? $this->client->shipping_state : $this->client->state, "admin_area_1" => strlen($this->client->shipping_state ?? '') > 1 ? $this->client->shipping_state : $this->client->state,
"postal_code" => strlen($this->client->shipping_postal_code) > 1 ? $this->client->shipping_postal_code : $this->client->postal_code, "postal_code" => strlen($this->client->shipping_postal_code ?? '') > 1 ? $this->client->shipping_postal_code : $this->client->postal_code,
"country_code" => $this->client->present()->shipping_country_code(), "country_code" => $this->client->present()->shipping_country_code(),
], ],
]]; ]];
@ -406,21 +405,32 @@ class PayPalPPCPPaymentDriver extends BaseDriver
private function injectPayPalPaymentSource(): array private function injectPayPalPaymentSource(): array
{ {
return [ $order = [
"paypal" => [ "paypal" => [
"name" => [ "name" => [
"given_name" => $this->client->present()->first_name(), "given_name" => $this->client->present()->first_name(),
"surname" => $this->client->present()->last_name(), "surname" => $this->client->present()->last_name(),
], ],
"email_address" => $this->client->present()->email(), "email_address" => $this->client->present()->email(),
"address" => $this->getBillingAddress(),
"experience_context" => [ "experience_context" => [
"user_action" => "PAY_NOW" "user_action" => "PAY_NOW"
], ],
], ],
]; ];
if(
strlen($this->client->address1 ?? '') > 2 &&
strlen($this->client->city ?? '') > 2 &&
strlen($this->client->state ?? '') >= 2 &&
strlen($this->client->postal_code ?? '') > 2 &&
strlen($this->client->country->iso_3166_2 ?? '') >= 2
)
{
$order["paypal"]["address"] = $this->getBillingAddress();
}
return $order;
} }
/** /**
@ -488,8 +498,6 @@ class PayPalPPCPPaymentDriver extends BaseDriver
$r = $this->gatewayRequest('/v2/checkout/orders', 'post', $order); $r = $this->gatewayRequest('/v2/checkout/orders', 'post', $order);
// nlog($r->json());
return $r->json()['id']; return $r->json()['id'];
} }
@ -497,14 +505,14 @@ class PayPalPPCPPaymentDriver extends BaseDriver
private function getBillingAddress(): array private function getBillingAddress(): array
{ {
return return
[ [
"address_line_1" => $this->client->address1, "address_line_1" => $this->client->address1,
"address_line_2" => $this->client->address2, "address_line_2" => $this->client->address2,
"admin_area_2" => $this->client->city, "admin_area_2" => $this->client->city,
"admin_area_1" => $this->client->state, "admin_area_1" => $this->client->state,
"postal_code" => $this->client->postal_code, "postal_code" => $this->client->postal_code,
"country_code" => $this->client->country->iso_3166_2, "country_code" => $this->client->country->iso_3166_2,
]; ];
} }
private function getShippingAddress(): ?array private function getShippingAddress(): ?array
@ -513,11 +521,11 @@ class PayPalPPCPPaymentDriver extends BaseDriver
[ [
"address" => "address" =>
[ [
"address_line_1" => strlen($this->client->shipping_address1) > 1 ? $this->client->shipping_address1 : $this->client->address1, "address_line_1" => strlen($this->client->shipping_address1 ?? '') > 1 ? $this->client->shipping_address1 : $this->client->address1,
"address_line_2" => $this->client->shipping_address2, "address_line_2" => $this->client->shipping_address2,
"admin_area_2" => strlen($this->client->shipping_city) > 1 ? $this->client->shipping_city : $this->client->city, "admin_area_2" => strlen($this->client->shipping_city ?? '') > 1 ? $this->client->shipping_city : $this->client->city,
"admin_area_1" => strlen($this->client->shipping_state) > 1 ? $this->client->shipping_state : $this->client->state, "admin_area_1" => strlen($this->client->shipping_state ?? '') > 1 ? $this->client->shipping_state : $this->client->state,
"postal_code" => strlen($this->client->shipping_postal_code) > 1 ? $this->client->shipping_postal_code : $this->client->postal_code, "postal_code" => strlen($this->client->shipping_postal_code ?? '') > 1 ? $this->client->shipping_postal_code : $this->client->postal_code,
"country_code" => $this->client->present()->shipping_country_code(), "country_code" => $this->client->present()->shipping_country_code(),
], ],
] ]

View File

@ -491,7 +491,24 @@ return render('gateways.paypal.pay', $data);
], ],
]; ];
/** If we have a complete address, add it to the order, otherwise leave it blank! */
if( if(
strlen($this->client->shipping_address1 ?? '') > 2 &&
strlen($this->client->shipping_city ?? '') > 2 &&
strlen($this->client->shipping_state ?? '') >= 2 &&
strlen($this->client->shipping_postal_code ?? '') > 2 &&
strlen($this->client->shipping_country->iso_3166_2 ?? '') >= 2
) {
$order['paypal']['address'] = [
"address_line_1" => $this->client->shipping_address1,
"address_line_2" => $this->client->shipping_address2,
"admin_area_2" => $this->client->shipping_city,
"admin_area_1" => $this->client->shipping_state,
"postal_code" => $this->client->shipping_postal_code,
"country_code" => $this->client->present()->shipping_country_code(),
];
}
elseif(
strlen($this->client->address1 ?? '') > 2 && strlen($this->client->address1 ?? '') > 2 &&
strlen($this->client->city ?? '') > 2 && strlen($this->client->city ?? '') > 2 &&
strlen($this->client->state ?? '') >= 2 && strlen($this->client->state ?? '') >= 2 &&
@ -533,7 +550,6 @@ return render('gateways.paypal.pay', $data);
"custom_id" => $this->payment_hash->hash, "custom_id" => $this->payment_hash->hash,
"description" => ctrans('texts.invoice_number') . '# ' . $invoice->number, "description" => ctrans('texts.invoice_number') . '# ' . $invoice->number,
"invoice_id" => $invoice->number, "invoice_id" => $invoice->number,
$this->getShippingAddress(),
"amount" => [ "amount" => [
"value" => (string) $data['amount_with_fee'], "value" => (string) $data['amount_with_fee'],
"currency_code" => $this->client->currency()->code, "currency_code" => $this->client->currency()->code,
@ -566,13 +582,9 @@ return render('gateways.paypal.pay', $data);
if(isset($data['payment_source'])) if(isset($data['payment_source']))
$order['payment_source'] = $data['payment_source']; $order['payment_source'] = $data['payment_source'];
nlog($order);
$r = $this->gatewayRequest('/v2/checkout/orders', 'post', $order); $r = $this->gatewayRequest('/v2/checkout/orders', 'post', $order);
// nlog($r->json());
return $r->json()['id']; return $r->json()['id'];
} }