Updates for PayPal PPCP

This commit is contained in:
David Bomba 2023-11-22 14:06:51 +11:00
parent dd9cfe64d6
commit e37c11499c
3 changed files with 93 additions and 26 deletions

View File

@ -110,6 +110,11 @@ class ClientPresenter extends EntityPresenter
return $str; return $str;
} }
public function shipping_country_code(): string
{
return $this->entity->shipping_country ? $this->entity->shipping_country->iso_3166_2 : $this->entity->country->iso_3166_2;
}
public function phone() public function phone()
{ {
return $this->entity->phone ?: ''; return $this->entity->phone ?: '';

View File

@ -87,8 +87,8 @@ class PayPalPPCPPaymentDriver extends BaseDriver
$method = PaymentType::PAYPAL; $method = PaymentType::PAYPAL;
match($gateway_type_id){ match($gateway_type_id){
"3" => $method = PaymentType::PAYPAL,
"1" => $method = PaymentType::CREDIT_CARD_OTHER, "1" => $method = PaymentType::CREDIT_CARD_OTHER,
"3" => $method = PaymentType::PAYPAL,
"25" => $method = PaymentType::VENMO, "25" => $method = PaymentType::VENMO,
}; };
@ -99,8 +99,8 @@ class PayPalPPCPPaymentDriver extends BaseDriver
{ {
$enums = [ $enums = [
3 => 'paypal',
1 => 'card', 1 => 'card',
3 => 'paypal',
25 => 'venmo', 25 => 'venmo',
// 9 => 'sepa', // 9 => 'sepa',
// 12 => 'bancontact', // 12 => 'bancontact',
@ -301,6 +301,63 @@ class PayPalPPCPPaymentDriver extends BaseDriver
} }
} }
private function paymentSource(): array
{
return match($this->paypal_payment_method) {
'paypal' => $this->injectPayPalPaymentSource(),
'card' => $this->injectCardPaymentSource(),
'venmo' => $this->injectVenmoPaymentSource(),
};
}
private function injectVenmoPaymentSource(): array
{
return [
"venmo" => [
"email_address" => $this->client->present()->email(),
],
];
}
private function injectCardPaymentSource(): array
{
return [
"card" => [
"name" => $this->client->present()->name(),
"email_address" => $this->client->present()->email(),
"billing_address" => $this->getBillingAddress(),
"experience_context"=> [
"user_action" => "PAY_NOW"
],
],
];
}
private function injectPayPalPaymentSource(): array
{
return [
"paypal" => [
"name" => [
"given_name" => $this->client->present()->first_name(),
"surname" => $this->client->present()->last_name(),
],
"email_address" => $this->client->present()->email(),
"address" => $this->getBillingAddress(),
"experience_context"=> [
"user_action" => "PAY_NOW"
],
],
];
}
private function createOrder(array $data): string private function createOrder(array $data): string
{ {
@ -315,14 +372,15 @@ class PayPalPPCPPaymentDriver extends BaseDriver
$order = [ $order = [
"intent" => "CAPTURE", "intent" => "CAPTURE",
"payer" => [ "payment_source" => $this->paymentSource(),
"name" => [ // "payer" => [
"given_name" => $this->client->present()->first_name(), // "name" => [
"surname" => $this->client->present()->last_name(), // "given_name" => $this->client->present()->first_name(),
], // "surname" => $this->client->present()->last_name(),
"email_address" => $this->client->present()->email(), // ],
"address" => $this->getBillingAddress(), // "email_address" => $this->client->present()->email(),
], // "address" => $this->getBillingAddress(),
// ],
"purchase_units" => [ "purchase_units" => [
[ [
"description" =>ctrans('texts.invoice_number').'# '.$invoice->number, "description" =>ctrans('texts.invoice_number').'# '.$invoice->number,
@ -333,9 +391,7 @@ class PayPalPPCPPaymentDriver extends BaseDriver
"payment_instruction" => [ "payment_instruction" => [
"disbursement_mode" => "INSTANT", "disbursement_mode" => "INSTANT",
], ],
"shipping" => [ $this->getShippingAddress(),
"address" => $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,
@ -385,15 +441,21 @@ class PayPalPPCPPaymentDriver extends BaseDriver
private function getShippingAddress(): array private function getShippingAddress(): array
{ {
return $this->company_gateway->require_shipping_address ? return $this->company_gateway->require_shipping_address ?
[ [
"address_line_1" => $this->client->shipping_address1, "shipping" => [
"address_line_2" => $this->client->shipping_address2, "address" =>
"admin_area_2" => $this->client->shipping_city, [
"admin_area_1" => $this->client->shipping_state, "address_line_1" => $this->client->shipping_address1,
"postal_code" => $this->client->shipping_postal_code, "address_line_2" => $this->client->shipping_address2,
"country_code" => $this->client->shipping_country->iso_3166_2, "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(),
],
] ]
]
: []; : [];
} }
public function gatewayRequest(string $uri, string $verb, array $data, ?array $headers = []) public function gatewayRequest(string $uri, string $verb, array $data, ?array $headers = [])

View File

@ -290,12 +290,12 @@ class EventServiceProvider extends ServiceProvider
*/ */
protected $listen = [ protected $listen = [
// RequestSending::class => [ RequestSending::class => [
// LogRequestSending::class, LogRequestSending::class,
// ], ],
// ResponseReceived::class => [ ResponseReceived::class => [
// LogResponseReceived::class, LogResponseReceived::class,
// ], ],
AccountCreated::class => [ AccountCreated::class => [
], ],
MessageSending::class => [ MessageSending::class => [