mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
wip
This commit is contained in:
parent
7711a21429
commit
83a42cf410
@ -260,24 +260,12 @@ class PaymentController extends Controller
|
||||
return $this->processCreditPayment($request, $data);
|
||||
}
|
||||
|
||||
try {
|
||||
return $gateway
|
||||
->driver(auth()->user()->client)
|
||||
->setPaymentMethod($payment_method_id)
|
||||
->setPaymentHash($payment_hash)
|
||||
->checkRequirements()
|
||||
->processPaymentView($data);
|
||||
} catch (\Exception $e) {
|
||||
SystemLogger::dispatch(
|
||||
$e->getMessage(),
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_ERROR,
|
||||
SystemLog::TYPE_FAILURE,
|
||||
auth('contact')->user()->client
|
||||
);
|
||||
|
||||
throw new PaymentFailed($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function response(PaymentResponseRequest $request)
|
||||
@ -286,24 +274,12 @@ class PaymentController extends Controller
|
||||
|
||||
$payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->payment_hash])->first();
|
||||
|
||||
try {
|
||||
return $gateway
|
||||
->driver(auth()->user()->client)
|
||||
->setPaymentMethod($request->input('payment_method_id'))
|
||||
->setPaymentHash($payment_hash)
|
||||
->checkRequirements()
|
||||
->processPaymentResponse($request);
|
||||
} catch (\Exception $e) {
|
||||
SystemLogger::dispatch(
|
||||
$e->getMessage(),
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_FAILURE,
|
||||
SystemLog::TYPE_FAILURE,
|
||||
auth('contact')->user()->client
|
||||
);
|
||||
|
||||
throw new PaymentFailed($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,15 +82,6 @@ class CreditCard
|
||||
{
|
||||
$this->checkout->init();
|
||||
|
||||
$cgt = ClientGatewayToken::query()
|
||||
->where('id', $this->decodePrimaryKey($request->input('token')))
|
||||
->where('company_id', auth('contact')->user()->client->company->id)
|
||||
->first();
|
||||
|
||||
if (!$cgt) {
|
||||
throw new PaymentFailed(ctrans('texts.payment_token_not_found'), 401);
|
||||
}
|
||||
|
||||
$state = [
|
||||
'server_response' => json_decode($request->gateway_response),
|
||||
'value' => $request->value,
|
||||
@ -103,12 +94,11 @@ class CreditCard
|
||||
|
||||
$state = array_merge($state, $request->all());
|
||||
$state['store_card'] = boolval($state['store_card']);
|
||||
$state['token'] = $cgt;
|
||||
|
||||
$this->checkout->payment_hash->data = array_merge((array)$this->checkout->payment_hash->data, $state);
|
||||
$this->checkout->payment_hash->save();
|
||||
|
||||
if ($request->has('token')) {
|
||||
if ($request->has('token') && !is_null($request->token) && !empty($request->token)) {
|
||||
return $this->attemptPaymentUsingToken($request);
|
||||
}
|
||||
|
||||
@ -117,7 +107,16 @@ class CreditCard
|
||||
|
||||
private function attemptPaymentUsingToken(PaymentResponseRequest $request)
|
||||
{
|
||||
$method = new IdSource($this->checkout->payment_hash->data->token->token);
|
||||
$cgt = ClientGatewayToken::query()
|
||||
->where('id', $this->decodePrimaryKey($request->input('token')))
|
||||
->where('company_id', auth('contact')->user()->client->company->id)
|
||||
->first();
|
||||
|
||||
if (!$cgt) {
|
||||
throw new PaymentFailed(ctrans('texts.payment_token_not_found'), 401);
|
||||
}
|
||||
|
||||
$method = new IdSource($cgt->token);
|
||||
|
||||
return $this->completePayment($method, $request);
|
||||
}
|
||||
@ -161,7 +160,7 @@ class CreditCard
|
||||
}
|
||||
|
||||
if ($response->status == 'Pending') {
|
||||
$this->checkout->confirmGatewayFee($request);
|
||||
$this->checkout->confirmGatewayFee();
|
||||
|
||||
return $this->processPendingPayment($response);
|
||||
}
|
||||
@ -171,7 +170,6 @@ class CreditCard
|
||||
|
||||
PaymentFailureMailer::dispatch($this->checkout->client, $response->response_summary, $this->checkout->client->company, $this->checkout->payment_hash->data->value);
|
||||
|
||||
|
||||
return $this->processUnsuccessfulPayment($response);
|
||||
}
|
||||
} catch (CheckoutHttpException $e) {
|
||||
|
@ -66,6 +66,7 @@ trait Utilities
|
||||
'payment_type' => PaymentType::parseCardType(strtolower($_payment->source['scheme'])),
|
||||
'amount' => $this->getParent()->payment_hash->data->raw_value,
|
||||
'transaction_reference' => $_payment->id,
|
||||
'gateway_type_id' => GatewayType::CREDIT_CARD,
|
||||
];
|
||||
|
||||
$payment = $this->getParent()->createPayment($data, \App\Models\Payment::STATUS_COMPLETED);
|
||||
|
@ -1,5 +1,8 @@
|
||||
{
|
||||
"video": false,
|
||||
"baseUrl": "http://localhost:8000/",
|
||||
"chromeWebSecurity": false
|
||||
"baseUrl": "http://localhost:8080/",
|
||||
"chromeWebSecurity": false,
|
||||
"env": {
|
||||
"runningEnvironment": "docker"
|
||||
}
|
||||
}
|
||||
|
21
cypress/integration/client_portal/checkout_credit_card.spec.js
vendored
Normal file
21
cypress/integration/client_portal/checkout_credit_card.spec.js
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
context('Checkout.com gateway test', () => {
|
||||
beforeEach(() => {
|
||||
cy.viewport('macbook-13');
|
||||
});
|
||||
|
||||
it('should migrate & seed checkout', function () {
|
||||
// cy.artisan('migrate:fresh --seed');
|
||||
// cy.artisan('ninja:create-single-account');
|
||||
cy.clientLogin();
|
||||
|
||||
cy.get('[data-cy=pay-now]').first().click();
|
||||
cy.get('[data-cy=pay-now-dropdown]').click();
|
||||
cy.get('[data-cy=pay-with-0]').click();
|
||||
|
||||
cy.getWithinIframe('#checkout-frames-card-number').type('4242424242424242');
|
||||
cy.getWithinIframe('#checkout-frames-expiry-date').type('12/30');
|
||||
cy.getWithinIframe('#checkout-frames-cvv').type('100');
|
||||
|
||||
cy.get('#pay-button').click();
|
||||
});
|
||||
});
|
35
cypress/support/account.js
vendored
Normal file
35
cypress/support/account.js
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const baseUrl = Cypress.config().baseUrl.endsWith('/')
|
||||
? Cypress.config().baseUrl.slice(0, -1)
|
||||
: Cypress.config().baseUrl;
|
||||
|
||||
Cypress.Commands.add('createAdminAccount', () => {
|
||||
let body = {
|
||||
first_name: "Cypress",
|
||||
last_name: "Testing",
|
||||
email: "cypress_testing@example.com",
|
||||
password: "password",
|
||||
terms_of_service: true,
|
||||
privacy_policy: true,
|
||||
report_errors: true,
|
||||
};
|
||||
|
||||
let headers = {
|
||||
"Content-Type": "application/json",
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
};
|
||||
|
||||
return axios.post(`${baseUrl}/api/v1/signup?first_load=true`, body, headers)
|
||||
.then(response => {
|
||||
console.log('Data from the request', response.data.data[0]);
|
||||
return response.data.data[0];
|
||||
})
|
||||
.catch(e => {
|
||||
throw "Unable to create an account for admin.";
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('createClientAccount', () => {
|
||||
// ..
|
||||
});
|
6
cypress/support/artisan.js
vendored
Normal file
6
cypress/support/artisan.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
Cypress.Commands.add('artisan', (cmd) => {
|
||||
let environment = Cypress.env('runningEnvironment');
|
||||
let prefix = environment === 'docker' ? 'docker-compose run --rm artisan' : 'php artisan';
|
||||
|
||||
return cy.exec(`${prefix} ${cmd}`);
|
||||
});
|
4
cypress/support/index.js
vendored
4
cypress/support/index.js
vendored
@ -14,7 +14,9 @@
|
||||
// ***********************************************************
|
||||
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import './commands'
|
||||
import './commands';
|
||||
import './artisan';
|
||||
import './account';
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
|
@ -24,7 +24,7 @@
|
||||
<div x-data="{ open: false }" @keydown.window.escape="open = false" @click.away="open = false" class="relative inline-block text-left" data-cy="payment-methods-dropdown">
|
||||
<div>
|
||||
<div class="rounded-md shadow-sm">
|
||||
<button @click="open = !open" type="button" class="inline-flex justify-center w-full px-4 py-2 text-sm font-medium leading-5 text-gray-700 transition duration-150 ease-in-out bg-white border border-gray-300 rounded-md hover:text-gray-500 focus:outline-none focus:border-blue-300 focus:shadow-outline-blue active:bg-gray-50 active:text-gray-800">
|
||||
<button data-cy="pay-now-dropdown" @click="open = !open" type="button" class="inline-flex justify-center w-full px-4 py-2 text-sm font-medium leading-5 text-gray-700 transition duration-150 ease-in-out bg-white border border-gray-300 rounded-md hover:text-gray-500 focus:outline-none focus:border-blue-300 focus:shadow-outline-blue active:bg-gray-50 active:text-gray-800">
|
||||
{{ ctrans('texts.pay_now') }}
|
||||
<svg class="w-5 h-5 ml-2 -mr-1" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
|
||||
@ -35,13 +35,13 @@
|
||||
<div x-show="open" class="absolute right-0 w-56 mt-2 origin-top-right rounded-md shadow-lg">
|
||||
<div class="bg-white rounded-md shadow-xs">
|
||||
<div class="py-1">
|
||||
@foreach($payment_methods as $payment_method)
|
||||
@foreach($payment_methods as $index => $payment_method)
|
||||
@if($payment_method['label'] == 'Custom')
|
||||
<a href="#" @click="{ open = false }" data-company-gateway-id="{{ $payment_method['company_gateway_id'] }}" data-gateway-type-id="{{ $payment_method['gateway_type_id'] }}" class="block px-4 py-2 text-sm leading-5 text-gray-700 dropdown-gateway-button hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900" data-cy="payment-method">
|
||||
<a href="#" @click="{ open = false }" data-cy="pay-with-custom" data-company-gateway-id="{{ $payment_method['company_gateway_id'] }}" data-gateway-type-id="{{ $payment_method['gateway_type_id'] }}" class="block px-4 py-2 text-sm leading-5 text-gray-700 dropdown-gateway-button hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900" data-cy="payment-method">
|
||||
{{ \App\Models\CompanyGateway::find($payment_method['company_gateway_id'])->firstOrFail()->getConfigField('name') }}
|
||||
</a>
|
||||
@elseif($total > 0)
|
||||
<a href="#" @click="{ open = false }" data-company-gateway-id="{{ $payment_method['company_gateway_id'] }}" data-gateway-type-id="{{ $payment_method['gateway_type_id'] }}" class="block px-4 py-2 text-sm leading-5 text-gray-700 dropdown-gateway-button hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900" data-cy="payment-method">
|
||||
<a href="#" @click="{ open = false }" data-cy="pay-with-{{ $index }}" data-company-gateway-id="{{ $payment_method['company_gateway_id'] }}" data-gateway-type-id="{{ $payment_method['gateway_type_id'] }}" class="block px-4 py-2 text-sm leading-5 text-gray-700 dropdown-gateway-button hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900" data-cy="payment-method">
|
||||
{{ $payment_method['label'] }}
|
||||
</a>
|
||||
@endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user