From 4918269bf2f3ae8ea0f67675af69ac90498a6ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 1 Jul 2020 18:28:57 +0200 Subject: [PATCH] Testing adding Stripe credit card - Added: iframeLoaded method for Cypress - Fixed: saving payment method id for CreditCard.php - Added: chromeWebSecurity: false flag for insecure iframe connections - Formatted: payment_methods/index - Formatted: payment-methods-table.blade.php - Added: Test for adding credit card to Stripe - Fixed: Removing client gateway tokens --- .../ClientPortal/PaymentMethodController.php | 6 +- app/PaymentDrivers/Stripe/CreditCard.php | 4 +- cypress.json | 3 +- .../client_portal/payment_methods.spec.js | 29 ++++ cypress/support/commands.js | 30 ++++ .../livewire/payment-methods-table.blade.php | 129 +++++++++--------- .../ninja2020/payment_methods/index.blade.php | 10 +- 7 files changed, 134 insertions(+), 77 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index e57cc00007a2..ce830357c499 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -48,7 +48,7 @@ class PaymentMethodController extends Controller return $gateway ->driver(auth()->user()->client) - ->setPaymentMethod(GatewayType::BANK_TRANSFER) + ->setPaymentMethod(GatewayType::CREDIT_CARD) ->authorizeView($data); } @@ -64,7 +64,7 @@ class PaymentMethodController extends Controller return $gateway ->driver(auth()->user()->client) - ->setPaymentMethod(GatewayType::BANK_TRANSFER) + ->setPaymentMethod(GatewayType::CREDIT_CARD) ->authorizeResponse($request); } @@ -133,7 +133,7 @@ class PaymentMethodController extends Controller public function destroy(ClientGatewayToken $payment_method) { try { - event(new MethodDeleted($payment_method)); + event(new MethodDeleted($payment_method, auth('contact')->user()->company)); $payment_method->delete(); } catch (\Exception $e) { Log::error(json_encode($e)); diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index 6b039f7d0e1c..bfb73f4230cb 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -45,7 +45,7 @@ class CreditCard $server_response = json_decode($request->input('gateway_response')); $gateway_id = $request->input('gateway_id'); - $gateway_type_id = $request->input('gateway_type_id'); + $gateway_type_id = $request->input('payment_method_id'); $is_default = $request->input('is_default'); $payment_method = $server_response->payment_method; @@ -192,7 +192,7 @@ class CreditCard ]; SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client); - + return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); } diff --git a/cypress.json b/cypress.json index 27840c96436d..79a612a766cb 100644 --- a/cypress.json +++ b/cypress.json @@ -1,4 +1,5 @@ { "video": false, - "baseUrl": "http://invoiceninja.wip/" + "baseUrl": "http://invoiceninja.wip/", + "chromeWebSecurity": false } diff --git a/cypress/integration/client_portal/payment_methods.spec.js b/cypress/integration/client_portal/payment_methods.spec.js index 4c87e5547d04..76e998233070 100644 --- a/cypress/integration/client_portal/payment_methods.spec.js +++ b/cypress/integration/client_portal/payment_methods.spec.js @@ -19,6 +19,35 @@ context('Payment methods', () => { .should('contain.text', 'Payment Method'); }); + it('should add stripe credit card', () => { + cy.visit('/client/payment_methods'); + + cy.get('body') + .find('#add-payment-method') + .first() + .should('contain.text', 'Add Payment Method') + .click() + + cy.location().should(location => { + expect(location.pathname).to.eq('/client/payment_methods/create'); + }); + + cy.wait(3000); + + cy.get('#cardholder-name').type('Invoice Ninja'); + + cy.getWithinIframe('[name="cardnumber"]').type('4242424242424242'); + cy.getWithinIframe('[name="exp-date"]').type('2442'); + cy.getWithinIframe('[name="cvc"]').type('242'); + cy.getWithinIframe('[name="postal"]').type('12345'); + + cy.get('#card-button').click(); + + cy.location().should(location => { + expect(location.pathname).to.eq('/client/payment_methods'); + }); + }); + it('should have per page options dropdown', () => { cy.visit('/client/payment_methods'); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index ce95a4236311..67b07104f176 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -44,3 +44,33 @@ Cypress.Commands.add('clientLogin', () => { }); }); }); + +Cypress.Commands.add( + 'iframeLoaded', + {prevSubject: 'element'}, + ($iframe) => { + const contentWindow = $iframe.prop('contentWindow'); + return new Promise(resolve => { + if ( + contentWindow + ) { + resolve(contentWindow) + } else { + $iframe.on('load', () => { + resolve(contentWindow) + }) + } + }) + }); + + +Cypress.Commands.add( + 'getInDocument', + {prevSubject: 'Permission denied to access property "document" on cross-origin object'}, + (document, selector) => Cypress.$(selector, document) +); + +Cypress.Commands.add( + 'getWithinIframe', + (targetElement) => cy.get('iframe').iframeLoaded().its('document').getInDocument(targetElement) +); diff --git a/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php b/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php index 7aa58605bd40..1295d1243966 100644 --- a/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/payment-methods-table.blade.php @@ -10,81 +10,85 @@ @if($client->getCreditCardGateway()) - {{ ctrans('texts.add_payment_method') }} + {{ ctrans('texts.add_payment_method') }} @endif
- - + - + - - - - - - + + + + + + + - @forelse($payment_methods as $payment_method) - - - - - - - - - - @empty - - - - @endforelse + @forelse($payment_methods as $payment_method) + + + + + + + + + + @empty + + + + @endforelse
+
{{ ctrans('texts.created_at') }} - + {{ ctrans('texts.payment_type_id') }} - - {{ ctrans('texts.type') }} - - {{ ctrans('texts.expires') }} - - {{ ctrans('texts.card_number') }} - - {{ ctrans('texts.default') }} -
+ {{ ctrans('texts.type') }} + + {{ ctrans('texts.expires') }} + + {{ ctrans('texts.card_number') }} + + {{ ctrans('texts.default') }} +
- {{ $payment_method->formatDateTimestamp($payment_method->created_at, $client->date_format()) }} - - {{ ctrans("texts.{$payment_method->gateway_type->alias}") }} - - {{ ucfirst(optional($payment_method->meta)->brand) }} - - @if(isset($payment_method->meta->exp_month) && isset($payment_method->meta->exp_year)) - {{ $payment_method->meta->exp_month}} / {{ $payment_method->meta->exp_year }} - @endif - - @isset($payment_method->meta->last4) - **** {{ $payment_method->meta->last4 }} - @endisset - - @if($payment_method->is_default) - - - - @endif - - - @lang('texts.view') - -
- {{ ctrans('texts.no_results') }} -
+ {{ $payment_method->formatDateTimestamp($payment_method->created_at, $client->date_format()) }} + + {{ ctrans("texts.{$payment_method->gateway_type->alias}") }} + + {{ ucfirst(optional($payment_method->meta)->brand) }} + + @if(isset($payment_method->meta->exp_month) && isset($payment_method->meta->exp_year)) + {{ $payment_method->meta->exp_month}} / {{ $payment_method->meta->exp_year }} + @endif + + @isset($payment_method->meta->last4) + **** {{ $payment_method->meta->last4 }} + @endisset + + @if($payment_method->is_default) + + + + @endif + + + @lang('texts.view') + +
+ {{ ctrans('texts.no_results') }} +
@@ -95,6 +99,7 @@ {{ ctrans('texts.showing_x_of', ['first' => $payment_methods->firstItem(), 'last' => $payment_methods->lastItem(), 'total' => $payment_methods->total()]) }} @endif + {{ $payment_methods->links() }}
- \ No newline at end of file + diff --git a/resources/views/portal/ninja2020/payment_methods/index.blade.php b/resources/views/portal/ninja2020/payment_methods/index.blade.php index 4a988b9d5eee..b265cbdcd0ff 100644 --- a/resources/views/portal/ninja2020/payment_methods/index.blade.php +++ b/resources/views/portal/ninja2020/payment_methods/index.blade.php @@ -1,16 +1,8 @@ @extends('portal.ninja2020.layout.app') @section('meta_title', ctrans('texts.payment_methods')) -@section('header') -
-
- -
-
-@endsection - @section('body')
@livewire('payment-methods-table', ['client' => $client])
-@endsection \ No newline at end of file +@endsection