From 7a4cfbe7ccc6d0d77fa62837c41f8a213bd59305 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 21 Jun 2023 21:11:41 +1000 Subject: [PATCH] Working on Paypal REST integration --- .../PayPalRestPaymentDriver.php | 37 ++- app/Utils/Traits/Inviteable.php | 2 + .../ninja2020/gateways/paypal/pay.blade.php | 230 ++++-------------- 3 files changed, 69 insertions(+), 200 deletions(-) diff --git a/app/PaymentDrivers/PayPalRestPaymentDriver.php b/app/PaymentDrivers/PayPalRestPaymentDriver.php index 935181d99d8f..50925d760ea3 100644 --- a/app/PaymentDrivers/PayPalRestPaymentDriver.php +++ b/app/PaymentDrivers/PayPalRestPaymentDriver.php @@ -100,20 +100,35 @@ class PayPalRestPaymentDriver extends BaseDriver public function processPaymentResponse($request) { - $this->init(); - - nlog($request->all()); $response = json_decode($request['gateway_response'], true); - $order_id = $response['orderID']; + if($response['status'] == 'COMPLETED'){ - nlog($order_id); + $data = [ + 'payment_type' => PaymentType::PAYPAL, + 'amount' => $response['purchase_units'][0]['amount']['value'], + 'transaction_reference' => $response['purchase_units'][0]['payments']['captures'][0]['id'], + 'gateway_type_id' => GatewayType::PAYPAL, + ]; - $r = $this->gatewayRequest("/v2/checkout/orders/{$order_id}/capture", 'post', []); + $payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); - dd($r->body()); + SystemLogger::dispatch( + ['response' => $response, 'data' => $data], + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_SUCCESS, + SystemLog::TYPE_PAYPAL, + $this->client, + $this->client->company, + ); + return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]); + + } + else { + throw new PaymentFailed('Payment failed. Please try again.', 401); + } } private function getClientToken(): string @@ -141,10 +156,10 @@ class PayPalRestPaymentDriver extends BaseDriver [ "description" =>ctrans('texts.invoice_number').'# '.$invoice->number, "invoice_id" => $invoice->number, - 'reference_id' => 'PUHF', - 'description' => 'Sporting Goods', - 'custom_id' => 'CUST-HighFashions', - 'soft_descriptor' => 'HighFashions', + // 'reference_id' => 'PUHF', + // 'description' => 'Sporting Goods', + // 'custom_id' => 'CUST-HighFashions', + // 'soft_descriptor' => 'HighFashions', "amount" => [ "value" => (string)$data['amount_with_fee'], "currency_code"=> $this->client->currency()->code, diff --git a/app/Utils/Traits/Inviteable.php b/app/Utils/Traits/Inviteable.php index 98584eed484a..f85f64be339b 100644 --- a/app/Utils/Traits/Inviteable.php +++ b/app/Utils/Traits/Inviteable.php @@ -68,6 +68,8 @@ trait Inviteable $qr = $writer->writeString($this->getPaymentLink(), 'utf-8'); + return "
$qr
"; + return " {$qr}"; } diff --git a/resources/views/portal/ninja2020/gateways/paypal/pay.blade.php b/resources/views/portal/ninja2020/gateways/paypal/pay.blade.php index b7f6dbffe518..82de6e218bfc 100644 --- a/resources/views/portal/ninja2020/gateways/paypal/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/paypal/pay.blade.php @@ -21,87 +21,7 @@
-
-
- -
-
-
- -
-
-
- -
-
-
- - -
- - -
-
- - -
-
- -
-
- -
-
- -
-
- -
-

- -
+ @endsection @section('gateway_footer') @@ -113,122 +33,54 @@ @endpush \ No newline at end of file