From c4f777b20ec6b7f70d9fb45cb44dca5d0dd11c73 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Sep 2019 15:27:05 +1000 Subject: [PATCH] Working on paypal response --- app/PaymentDrivers/BasePaymentDriver.php | 29 +++++++++++++------ .../PayPalExpressPaymentDriver.php | 8 +++-- app/PaymentDrivers/StripePaymentDriver.php | 25 +++++----------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index 8d2f442d1a72..108d55aa404e 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -48,11 +48,13 @@ class BasePaymentDriver /* The Invitation */ protected $invitation; - /* Member variables */ + /* Gateway capabilities */ protected $refundable = false; + /* Token billing */ protected $token_billing = false; + /* Authorise payment methods */ protected $can_authorise_credit_card = false; @@ -61,7 +63,6 @@ class BasePaymentDriver $this->company_gateway = $company_gateway; $this->invitation = $invitation; $this->client = $client; - //$this->gatewayType = $gatewayType ?: $this->gatewayTypes()[0]; } /** @@ -70,7 +71,7 @@ class BasePaymentDriver */ protected function gateway() { -\Log::error("booting {$this->company_gateway->gateway->provider}"); + $this->gateway = Omnipay::create($this->company_gateway->gateway->provider); $this->gateway->initialize((array) $this->company_gateway->getConfig()); @@ -91,14 +92,14 @@ class BasePaymentDriver /** * Returns the default gateway type */ - public function gatewayTypes() + public function gatewayTypes() { return [ GatewayType::CREDIT_CARD, ]; } - public function getCompanyGatewayId() + public function getCompanyGatewayId() :int { return $this->company_gateway->id; } @@ -106,7 +107,7 @@ class BasePaymentDriver * Returns whether refunds are possible with the gateway * @return boolean TRUE|FALSE */ - public function getRefundable() + public function getRefundable() :bool { return $this->refundable; } @@ -115,12 +116,17 @@ class BasePaymentDriver * Returns whether token billing is possible with the gateway * @return boolean TRUE|FALSE */ - public function getTokenBilling() + public function getTokenBilling() :bool { return $this->token_billing; } - public function canAuthoriseCreditCard() + /** + * Returns whether gateway can + * authorise and credit card. + * @return [type] [description] + */ + public function canAuthoriseCreditCard() :bool { return $this->can_authorise_credit_card; } @@ -139,6 +145,11 @@ class BasePaymentDriver public function processPaymentResponse($request) {} + /** + * Return the contact if possible + * + * @return ClientContact The ClientContact object + */ public function getContact() { if($this->invitation) @@ -184,7 +195,7 @@ class BasePaymentDriver return $data; } - public function offsitePurchase($data, $items) + public function purchase($data, $items) { $this->gateway(); diff --git a/app/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/PaymentDrivers/PayPalExpressPaymentDriver.php index d390c27d749a..b81c6975237e 100644 --- a/app/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -54,7 +54,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver */ public function processPaymentView(array $data) { - $this->offsitePurchase($this->paymentDetails($data), $this->paymentItems($data)); + $this->purchase($this->paymentDetails($data), $this->paymentItems($data)); } public function processPaymentResponse($request) @@ -62,7 +62,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver $response = $this->completePurchase($request->all()); - $paymentRef = $response->getTransactionReference() ?: $transRef; + $transaction_reference = $response->getTransactionReference() ?: $request->input('token'); if ($response->isCancelled()) { return false; @@ -168,4 +168,8 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver return $items; } + private function createPayment($data) + { + + } } \ No newline at end of file diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 2c5ef74534bd..b1498aaf05f7 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -360,27 +360,18 @@ class StripePaymentDriver extends BasePaymentDriver $payment->save(); -//mark all invoices as paid -//$invoices->update(['status_id' => Payment::STATUS_COMPLETED]); + /** + * Move this into an event + */ + $invoices->each(function ($invoice) use($payment) { - // foreach($invoices as $invoice){ - // \Log::error('invite count = '.$invoices->invitations->count()); - // foreach($invoice->invitations as $invitation) - // { - // \Log::error($invitation); - // $invitations->update(['transaction_reference' => $payment->transaction_reference]); - // } - // } + $invoice->status_id = Invoice::STATUS_PAID; + $invoice->save(); + $invoice->invitations()->update(['transaction_reference' => $payment->transaction_reference]); -//mark all invitations with transaction reference -//TODO move this to to be called from an event... doesn't belong here -$invoices->each(function ($invoice) use($payment) { + }); - $invoice->status_id = Payment::STATUS_COMPLETED; - $invoice->save(); - $invoice->invitations()->update(['transaction_reference' => $payment->transaction_reference]); -}); return redirect()->route('client.payments.show', ['id' => $this->encodePrimaryKey($payment->id)]); }