From 421327ae8e351b6606f2b9a512964b893308554e Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 5 Sep 2017 11:36:37 +0300 Subject: [PATCH] Working on Alipay --- app/Http/Controllers/ClientPortalController.php | 4 ---- app/Http/Controllers/OnlinePaymentController.php | 15 --------------- app/Http/routes.php | 1 - app/Ninja/PaymentDrivers/BasePaymentDriver.php | 11 ++++++----- app/Ninja/PaymentDrivers/StripePaymentDriver.php | 2 +- 5 files changed, 7 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index 91c1e0a345b8..0349e08c2904 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -69,10 +69,6 @@ class ClientPortalController extends BaseController $account->loadLocalizationSettings($client); - if (! Input::has('phantomjs')) { - $this->invoiceRepo->clearGatewayFee($invoice); - } - if (! Input::has('phantomjs') && ! session('silent:' . $client->id) && ! Session::has($invitation->invitation_key) && (! Auth::check() || Auth::user()->account_id != $invoice->account_id)) { if ($invoice->isType(INVOICE_TYPE_QUOTE)) { diff --git a/app/Http/Controllers/OnlinePaymentController.php b/app/Http/Controllers/OnlinePaymentController.php index 4fd72dacb516..ddba45b56ba7 100644 --- a/app/Http/Controllers/OnlinePaymentController.php +++ b/app/Http/Controllers/OnlinePaymentController.php @@ -198,21 +198,6 @@ class OnlinePaymentController extends BaseController } } - public function createSource($invitationKey, $gatewayType) - { - if (! $invitation = $this->invoiceRepo->findInvoiceByInvitation($invitationKey)) { - return response()->view('error', [ - 'error' => trans('texts.invoice_not_found'), - 'hideHeader' => true, - ]); - } - - $gatewayTypeId = GatewayType::getIdFromAlias($gatewayType); - $paymentDriver = $invitation->account->paymentDriver($invitation, $gatewayTypeId); - - return $paymentDriver->createSource(); - } - public function completeSource($invitationKey, $gatewayType) { if (! $invitation = $this->invoiceRepo->findInvoiceByInvitation($invitationKey)) { diff --git a/app/Http/routes.php b/app/Http/routes.php index ba3cfd75dab7..891c688b87e4 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -33,7 +33,6 @@ Route::group(['middleware' => ['lookup:contact', 'auth:client']], function () { Route::get('approve/{invitation_key}', 'QuoteController@approve'); Route::get('payment/{invitation_key}/{gateway_type?}/{source_id?}', 'OnlinePaymentController@showPayment'); Route::post('payment/{invitation_key}', 'OnlinePaymentController@doPayment'); - Route::get('create_source/{invitation_key}/{gateway_type}', 'OnlinePaymentController@createSource'); Route::get('complete_source/{invitation_key}/{gateway_type}', 'OnlinePaymentController@completeSource'); Route::match(['GET', 'POST'], 'complete/{invitation_key?}/{gateway_type?}', 'OnlinePaymentController@offsitePayment'); Route::get('bank/{routing_number}', 'OnlinePaymentController@getBankInfo'); diff --git a/app/Ninja/PaymentDrivers/BasePaymentDriver.php b/app/Ninja/PaymentDrivers/BasePaymentDriver.php index 35ead952f7b5..3ca97f6b21cd 100644 --- a/app/Ninja/PaymentDrivers/BasePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BasePaymentDriver.php @@ -141,6 +141,11 @@ class BasePaymentDriver $invoicRepo->setGatewayFee($this->invoice(), $this->gatewayType); } + // For these gateway types we use the API directrly rather than Omnipay + if (in_array($this->gatewayType, [GATEWAY_TYPE_ALIPAY])) { + return $this->createSource(); + } + if ($this->isGatewayType(GATEWAY_TYPE_TOKEN) || $gateway->is_offsite) { if (Session::has('error')) { Session::reflash(); @@ -937,11 +942,7 @@ class BasePaymentDriver $url = 'javascript:showCustomModal();'; $label = e($this->accountGateway->getConfigField('name')); } else { - if ($gatewayTypeId == GATEWAY_TYPE_ALIPAY) { - $url = url("/create_source/{$this->invitation->invitation_key}/alipay"); - } else { - $url = $this->paymentUrl($gatewayTypeAlias); - } + $url = $this->paymentUrl($gatewayTypeAlias); if ($custom = $this->account()->getLabel($gatewayTypeAlias)) { $label = $custom; } else { diff --git a/app/Ninja/PaymentDrivers/StripePaymentDriver.php b/app/Ninja/PaymentDrivers/StripePaymentDriver.php index f174652390ec..08ce70a0b087 100644 --- a/app/Ninja/PaymentDrivers/StripePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/StripePaymentDriver.php @@ -328,7 +328,7 @@ class StripePaymentDriver extends BasePaymentDriver $redirect = url("/complete_source/{$this->invitation->invitation_key}/{$gatewayType}"); $email = $this->contact()->email; - $data = "type=alipay&amount={$amount}¤cy={$currency}&redirect[return_url]={$redirect}&owner[email]={$email}"; + $data = "type=alipay&amount={$amount}¤cy={$currency}&redirect[return_url]={$redirect}"; $response = $this->makeStripeCall('POST', 'sources', $data); $this->invitation->transaction_reference = $response['id'];