mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-20 00:11:35 +02:00
Checkout v2 refactor
This commit is contained in:
parent
4606215ba2
commit
3f8449ba01
@ -14,17 +14,22 @@ namespace App\PaymentDrivers\CheckoutCom;
|
||||
|
||||
use App\Exceptions\PaymentFailed;
|
||||
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ClientGatewayToken;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\PaymentDrivers\CheckoutComPaymentDriver;
|
||||
use App\PaymentDrivers\Common\MethodInterface;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Checkout\CheckoutApiException;
|
||||
use Checkout\CheckoutArgumentException;
|
||||
use Checkout\CheckoutAuthorizationException;
|
||||
use Checkout\Common\CustomerRequest;
|
||||
use Checkout\Library\Exceptions\CheckoutHttpException;
|
||||
use Checkout\Models\Payments\IdSource;
|
||||
use Checkout\Models\Payments\Payment;
|
||||
use Checkout\Models\Payments\TokenSource;
|
||||
use Checkout\Payments\Four\Request\PaymentRequest;
|
||||
use Checkout\Payments\Four\Request\Source\RequestTokenSource;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CreditCard implements MethodInterface
|
||||
@ -57,6 +62,23 @@ class CreditCard implements MethodInterface
|
||||
return render('gateways.checkout.credit_card.authorize', $data);
|
||||
}
|
||||
|
||||
private function getCustomer()
|
||||
{
|
||||
try{
|
||||
|
||||
$response = $this->checkout->gateway->getCustomersClient()->get($this->checkout->client->present()->email());
|
||||
|
||||
return $response;
|
||||
}
|
||||
catch(\Exception $e){
|
||||
|
||||
$request = new CustomerRequest();
|
||||
$request->email = $this->checkout->client->present()->email();
|
||||
$request->name = $this->checkout->client->present()->name();
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle authorization for credit card.
|
||||
*
|
||||
@ -67,29 +89,43 @@ class CreditCard implements MethodInterface
|
||||
{
|
||||
$gateway_response = \json_decode($request->gateway_response);
|
||||
|
||||
$method = new TokenSource(
|
||||
$gateway_response->token
|
||||
);
|
||||
// $method = new TokenSource(
|
||||
// $gateway_response->token
|
||||
// );
|
||||
|
||||
$payment = new Payment($method, 'USD');
|
||||
$payment->amount = 100; // $1
|
||||
$payment->reference = '$1 payment for authorization.';
|
||||
$payment->capture = false;
|
||||
// $payment = new Payment($method, 'USD');
|
||||
// $payment->amount = 100; // $1
|
||||
// $payment->reference = '$1 payment for authorization.';
|
||||
// $payment->capture = false;
|
||||
|
||||
$customerRequest = $this->getCustomer();
|
||||
|
||||
$token_source = new RequestTokenSource();
|
||||
$token_source->token = $gateway_response->token;
|
||||
|
||||
$request = new PaymentRequest();
|
||||
$request->source = $token_source;
|
||||
$request->capture = false;
|
||||
$request->reference = '$1 payment for authorization.';
|
||||
$request->amount = 100;
|
||||
$request->currency = $this->checkout->client->getCurrencyCode();
|
||||
$request->customer = $customerRequest;
|
||||
|
||||
try {
|
||||
$response = $this->checkout->gateway->payments()->request($payment);
|
||||
$response = $this->checkout->gateway->getPaymentsClient()->requestPayment($request);
|
||||
|
||||
if ($response->approved && $response->status === 'Authorized') {
|
||||
|
||||
if ($response['approved'] && $response['status'] === 'Authorized') {
|
||||
$payment_meta = new \stdClass;
|
||||
$payment_meta->exp_month = (string) $response->source['expiry_month'];
|
||||
$payment_meta->exp_year = (string) $response->source['expiry_year'];
|
||||
$payment_meta->brand = (string) $response->source['scheme'];
|
||||
$payment_meta->last4 = (string) $response->source['last4'];
|
||||
$payment_meta->exp_month = (string) $response['source']['expiry_month'];
|
||||
$payment_meta->exp_year = (string) $response['source']['expiry_year'];
|
||||
$payment_meta->brand = (string) $response['source']['scheme'];
|
||||
$payment_meta->last4 = (string) $response['source']['last4'];
|
||||
$payment_meta->type = (int) GatewayType::CREDIT_CARD;
|
||||
|
||||
$data = [
|
||||
'payment_meta' => $payment_meta,
|
||||
'token' => $response->source['id'],
|
||||
'token' => $response['source']['id'],
|
||||
'payment_method_id' => GatewayType::CREDIT_CARD,
|
||||
];
|
||||
|
||||
@ -97,11 +133,51 @@ class CreditCard implements MethodInterface
|
||||
|
||||
return redirect()->route('client.payment_methods.show', $payment_method->hashed_id);
|
||||
}
|
||||
} catch (CheckoutHttpException $exception) {
|
||||
throw new PaymentFailed(
|
||||
$exception->getMessage()
|
||||
);
|
||||
|
||||
|
||||
} catch (CheckoutApiException $e) {
|
||||
// API error
|
||||
$request_id = $e->request_id;
|
||||
$http_status_code = $e->http_status_code;
|
||||
$error_details = $e->error_details;
|
||||
|
||||
dd($e);
|
||||
|
||||
} catch (CheckoutArgumentException $e) {
|
||||
// Bad arguments
|
||||
dd($e->getMessage());
|
||||
} catch (CheckoutAuthorizationException $e) {
|
||||
// Bad Invalid authorization
|
||||
dd($e->getMessage());
|
||||
|
||||
}
|
||||
|
||||
// try {
|
||||
// $response = $this->checkout->gateway->payments()->request($payment);
|
||||
|
||||
// if ($response->approved && $response->status === 'Authorized') {
|
||||
// $payment_meta = new \stdClass;
|
||||
// $payment_meta->exp_month = (string) $response->source['expiry_month'];
|
||||
// $payment_meta->exp_year = (string) $response->source['expiry_year'];
|
||||
// $payment_meta->brand = (string) $response->source['scheme'];
|
||||
// $payment_meta->last4 = (string) $response->source['last4'];
|
||||
// $payment_meta->type = (int) GatewayType::CREDIT_CARD;
|
||||
|
||||
// $data = [
|
||||
// 'payment_meta' => $payment_meta,
|
||||
// 'token' => $response->source['id'],
|
||||
// 'payment_method_id' => GatewayType::CREDIT_CARD,
|
||||
// ];
|
||||
|
||||
// $payment_method = $this->checkout->storeGatewayToken($data);
|
||||
|
||||
// return redirect()->route('client.payment_methods.show', $payment_method->hashed_id);
|
||||
// }
|
||||
// } catch (CheckoutHttpException $exception) {
|
||||
// throw new PaymentFailed(
|
||||
// $exception->getMessage()
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
public function paymentView($data)
|
||||
|
@ -28,10 +28,14 @@ use App\PaymentDrivers\CheckoutCom\CreditCard;
|
||||
use App\PaymentDrivers\CheckoutCom\Utilities;
|
||||
use App\Utils\Traits\SystemLogTrait;
|
||||
use Checkout\CheckoutApi;
|
||||
use Checkout\CheckoutDefaultSdk;
|
||||
use Checkout\CheckoutFourSdk;
|
||||
use Checkout\Environment;
|
||||
use Checkout\Library\Exceptions\CheckoutHttpException;
|
||||
use Checkout\Models\Payments\IdSource;
|
||||
use Checkout\Models\Payments\Refund;
|
||||
use Exception;
|
||||
use JmesPath\Env;
|
||||
|
||||
class CheckoutComPaymentDriver extends BaseDriver
|
||||
{
|
||||
@ -109,7 +113,21 @@ class CheckoutComPaymentDriver extends BaseDriver
|
||||
'sandbox' => $this->company_gateway->getConfigField('testMode'),
|
||||
];
|
||||
|
||||
$this->gateway = new CheckoutApi($config['secret'], $config['sandbox'], $config['public']);
|
||||
|
||||
if(strlen($config['secret']) === 35){
|
||||
$builder = CheckoutFourSdk::staticKeys();
|
||||
$builder->setPublicKey($config['public']); // optional, only required for operations related with tokens
|
||||
$builder->setSecretKey($config['secret']);
|
||||
$builder->setEnvironment($config['sandbox'] ? Environment::sandbox(): Environment::production());
|
||||
$this->gateway = $builder->build();
|
||||
}
|
||||
else {
|
||||
$builder = CheckoutDefaultSdk::staticKeys();
|
||||
$builder->setPublicKey($config['public']); // optional, only required for operations related with tokens
|
||||
$builder->setSecretKey($config['secret']);
|
||||
$builder->setEnvironment($config['sandbox'] ? Environment::sandbox(): Environment::production());
|
||||
$this->gateway = $builder->build();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@
|
||||
"bacon/bacon-qr-code": "^2.0",
|
||||
"beganovich/snappdf": "^1.7",
|
||||
"braintree/braintree_php": "^6.0",
|
||||
"checkout/checkout-sdk-php": "^1.0",
|
||||
"checkout/checkout-sdk-php": "^2.5",
|
||||
"cleverit/ubl_invoice": "^1.3",
|
||||
"coconutcraig/laravel-postmark": "^2.10",
|
||||
"doctrine/dbal": "^3.0",
|
||||
|
31
composer.lock
generated
31
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "c9278efe297c252de6bc0b5a48540c0b",
|
||||
"content-hash": "6845489fdc254427c4536e22f025ff51",
|
||||
"packages": [
|
||||
{
|
||||
"name": "afosto/yaac",
|
||||
@ -741,28 +741,37 @@
|
||||
},
|
||||
{
|
||||
"name": "checkout/checkout-sdk-php",
|
||||
"version": "1.0.19",
|
||||
"version": "2.5.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/checkout/checkout-sdk-php.git",
|
||||
"reference": "c2c323ea2f95f74bff3055c42801e7ce22999791"
|
||||
"reference": "097b862487f7583fd0fab47a08e3dc0800f5c3e4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/checkout/checkout-sdk-php/zipball/c2c323ea2f95f74bff3055c42801e7ce22999791",
|
||||
"reference": "c2c323ea2f95f74bff3055c42801e7ce22999791",
|
||||
"url": "https://api.github.com/repos/checkout/checkout-sdk-php/zipball/097b862487f7583fd0fab47a08e3dc0800f5c3e4",
|
||||
"reference": "097b862487f7583fd0fab47a08e3dc0800f5c3e4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
"ext-fileinfo": "*",
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/guzzle": "^6.5 || ^7.4",
|
||||
"monolog/monolog": "^1.27 || ^2.4",
|
||||
"php": ">=5.6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^6"
|
||||
"mockery/mockery": "^1.3 || ^1.4",
|
||||
"phpstan/phpstan": "^1.2",
|
||||
"phpunit/phpunit": "^5.7 || ^9.0",
|
||||
"smgladkovskiy/phpcs-git-pre-commit": "dev-master",
|
||||
"squizlabs/php_codesniffer": "^3.3",
|
||||
"symfony/phpunit-bridge": "^5.2 || ^6.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Checkout\\": "src/"
|
||||
"Checkout\\": "lib/Checkout"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
@ -772,7 +781,7 @@
|
||||
"authors": [
|
||||
{
|
||||
"name": "Checkout.com",
|
||||
"email": "platforms@checkout.com",
|
||||
"email": "integrations@checkout.com",
|
||||
"homepage": "https://github.com/checkout/checkout-sdk-php/graphs/contributors"
|
||||
}
|
||||
],
|
||||
@ -794,9 +803,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/checkout/checkout-sdk-php/issues",
|
||||
"source": "https://github.com/checkout/checkout-sdk-php/tree/1.0.19"
|
||||
"source": "https://github.com/checkout/checkout-sdk-php/tree/2.5.1"
|
||||
},
|
||||
"time": "2021-11-19T15:08:38+00:00"
|
||||
"time": "2022-06-13T00:23:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "cleverit/ubl_invoice",
|
||||
|
Loading…
Reference in New Issue
Block a user