diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index bd14c921c05d..8d2f442d1a72 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -208,5 +208,13 @@ class BasePaymentDriver $this->purchaseResponse = (array)$response->getData();*/ } + public function completePurchase($data) + { + $this->gateway(); + + return $this->gateway + ->completePurchase($data) + ->send(); + } } \ No newline at end of file diff --git a/app/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/PaymentDrivers/PayPalExpressPaymentDriver.php index bf5547e7f3d6..d390c27d749a 100644 --- a/app/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -60,6 +60,17 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver public function processPaymentResponse($request) { + $response = $this->completePurchase($request->all()); + + $paymentRef = $response->getTransactionReference() ?: $transRef; + + if ($response->isCancelled()) { + return false; + } elseif (! $response->isSuccessful()) { + throw new Exception($response->getMessage()); + } + + dd($response); } protected function paymentDetails($input) @@ -81,8 +92,9 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver private function buildReturnUrl($input) { - $url = $this->client->company->domain . "/payment_hook/{$this->company_gateway->id}/{GatewayType::PAYPAL}/"; - $url .= "?hashed_ids=" . implode(",", $input['hashed_ids']); + $url = $this->client->company->domain . "client/payments/process/response"; + $url .= "?company_gateway_id={$this->company_gateway->id}&gateway_type_id=".GatewayType::PAYPAL; + $url .= "&hashed_ids=" . implode(",", $input['hashed_ids']); $url .= "&amount=".$input['amount']; $url .= "&fee=".$input['fee']; diff --git a/routes/client.php b/routes/client.php index fa9d449541e4..ea00b342979b 100644 --- a/routes/client.php +++ b/routes/client.php @@ -27,6 +27,7 @@ Route::group(['middleware' => ['auth:contact'], 'prefix' => 'client', 'as' => 'c Route::get('payments/{payment}', 'ClientPortal\PaymentController@show')->name('payments.show'); Route::post('payments/process', 'ClientPortal\PaymentController@process')->name('payments.process'); Route::post('payments/process/response', 'ClientPortal\PaymentController@response')->name('payments.response'); + Route::get('payments/process/response', 'ClientPortal\PaymentController@response')->name('payments.response.get'); Route::get('profile/{client_contact}/edit', 'ClientPortal\ProfileController@edit')->name('profile.edit'); Route::put('profile/{client_contact}/edit', 'ClientPortal\ProfileController@update')->name('profile.update'); @@ -46,7 +47,7 @@ Route::group(['middleware' => ['domain_db'], 'prefix' => 'client', 'as' => 'clie /*Invitation catches*/ Route::get('invoice/{invitation_id}','ClientPortal\InvitationController@invoiceRouter'); - Route::get('payment_hook/{invitation_id}','ClientPortal\PaymentHookController@process'); + Route::get('payment_hook/{company_gateway_id}/{gateway_type_id}','ClientPortal\PaymentHookController@process'); });