mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 14:14:44 -04:00
Credit card 3ds processing
This commit is contained in:
parent
3d12fd80e8
commit
1e2e55c9e4
@ -14,11 +14,14 @@ namespace App\Http\Controllers\Gateways;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Gateways\Mollie\Mollie3dsRequest;
|
use App\Http\Requests\Gateways\Mollie\Mollie3dsRequest;
|
||||||
|
use App\Models\PaymentHash;
|
||||||
|
|
||||||
class Mollie3dsController extends Controller
|
class Mollie3dsController extends Controller
|
||||||
{
|
{
|
||||||
public function index(Mollie3dsRequest $request)
|
public function index(Mollie3dsRequest $request)
|
||||||
{
|
{
|
||||||
dd($request->all());
|
return $request->getCompanyGateway()
|
||||||
|
->driver($request->getClient())
|
||||||
|
->process3dsConfirmation($request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,18 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests\Gateways\Mollie;
|
namespace App\Http\Requests\Gateways\Mollie;
|
||||||
|
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\ClientGatewayToken;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\CompanyGateway;
|
||||||
|
use App\Models\PaymentHash;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
class Mollie3dsRequest extends FormRequest
|
class Mollie3dsRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
*
|
*
|
||||||
@ -23,7 +31,7 @@ class Mollie3dsRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,4 +45,29 @@ class Mollie3dsRequest extends FormRequest
|
|||||||
//
|
//
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCompany(): ?Company
|
||||||
|
{
|
||||||
|
return Company::where('company_key', $this->company_key)->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCompanyGateway(): ?CompanyGateway
|
||||||
|
{
|
||||||
|
return CompanyGateway::find($this->decodePrimaryKey($this->company_gateway_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPaymentHash(): ?PaymentHash
|
||||||
|
{
|
||||||
|
return PaymentHash::where('hash', $this->hash)->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClient(): ?Client
|
||||||
|
{
|
||||||
|
return Client::find($this->getPaymentHash()->data->client_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPaymentId(): ?string
|
||||||
|
{
|
||||||
|
return $this->getPaymentHash()->data->payment_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class PaymentHash extends Model
|
|||||||
return $this->belongsTo(Invoice::class, 'fee_invoice_id', 'id');
|
return $this->belongsTo(Invoice::class, 'fee_invoice_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withData(string $property, $value): PaymentHash
|
public function withData(string $property, $value): self
|
||||||
{
|
{
|
||||||
$this->data = array_merge((array) $this->data, [$property => $value]);
|
$this->data = array_merge((array) $this->data, [$property => $value]);
|
||||||
$this->save();
|
$this->save();
|
||||||
|
@ -50,21 +50,26 @@ class CreditCard
|
|||||||
*/
|
*/
|
||||||
public function paymentResponse(PaymentResponseRequest $request)
|
public function paymentResponse(PaymentResponseRequest $request)
|
||||||
{
|
{
|
||||||
$this->mollie->payment_hash->withData('gateway_type_id', GatewayType::CREDIT_CARD);
|
// TODO: Unit tests.
|
||||||
|
$amount = number_format((float) $this->mollie->payment_hash->data->amount_with_fee, 2, '.', '');
|
||||||
|
|
||||||
|
$this->mollie->payment_hash
|
||||||
|
->withData('gateway_type_id', GatewayType::CREDIT_CARD)
|
||||||
|
->withData('client_id', $this->mollie->client->id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$payment = $this->mollie->gateway->payments->create([
|
$payment = $this->mollie->gateway->payments->create([
|
||||||
'amount' => [
|
'amount' => [
|
||||||
'currency' => $this->mollie->client->currency()->code,
|
'currency' => $this->mollie->client->currency()->code,
|
||||||
'value' => Number::formatValue($this->mollie->payment_hash->data->amount_with_fee, $this->mollie->client->currency()),
|
'value' => $amount,
|
||||||
],
|
],
|
||||||
'description' => \sprintf('Hash: %s', $this->mollie->payment_hash->hash),
|
'description' => \sprintf('Hash: %s', $this->mollie->payment_hash->hash),
|
||||||
'redirectUrl' => 'https://webshop.example.org/order/12345/',
|
'redirectUrl' => route('mollie.3ds_redirect', [
|
||||||
'webhookUrl' => route('mollie.3ds_redirect', [
|
|
||||||
'company_key' => $this->mollie->client->company->company_key,
|
'company_key' => $this->mollie->client->company->company_key,
|
||||||
'company_gateway_id' => $this->mollie->company_gateway->hashed_id,
|
'company_gateway_id' => $this->mollie->company_gateway->hashed_id,
|
||||||
'hash' => $this->mollie->payment_hash->hash,
|
'hash' => $this->mollie->payment_hash->hash,
|
||||||
]),
|
]),
|
||||||
|
'webhookUrl' => 'https://invoiceninja.com',
|
||||||
'cardToken' => $request->token,
|
'cardToken' => $request->token,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -78,6 +83,8 @@ class CreditCard
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($payment->status === 'open') {
|
if ($payment->status === 'open') {
|
||||||
|
$this->mollie->payment_hash->withData('payment_id', $payment->id);
|
||||||
|
|
||||||
return redirect($payment->getCheckoutUrl());
|
return redirect($payment->getCheckoutUrl());
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -87,10 +94,8 @@ class CreditCard
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function processSuccessfulPayment(\Mollie\Api\Resources\Payment $payment)
|
public function processSuccessfulPayment(\Mollie\Api\Resources\Payment $payment)
|
||||||
{
|
{
|
||||||
// Check if storing credit card is enabled
|
|
||||||
|
|
||||||
$payment_hash = $this->mollie->payment_hash;
|
$payment_hash = $this->mollie->payment_hash;
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
@ -131,5 +136,7 @@ class CreditCard
|
|||||||
$this->mollie->client,
|
$this->mollie->client,
|
||||||
$this->mollie->client->company,
|
$this->mollie->client->company,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
throw new PaymentFailed($e->getMessage(), $e->getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
namespace App\PaymentDrivers;
|
namespace App\PaymentDrivers;
|
||||||
|
|
||||||
|
use App\Http\Requests\Gateways\Mollie\Mollie3dsRequest;
|
||||||
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
||||||
use App\Models\ClientGatewayToken;
|
use App\Models\ClientGatewayToken;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
@ -122,4 +123,19 @@ class MolliePaymentDriver extends BaseDriver
|
|||||||
public function processWebhookRequest(PaymentWebhookRequest $request, Payment $payment = null)
|
public function processWebhookRequest(PaymentWebhookRequest $request, Payment $payment = null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function process3dsConfirmation(Mollie3dsRequest $request)
|
||||||
|
{
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
$this->setPaymentHash($request->getPaymentHash());
|
||||||
|
|
||||||
|
try {
|
||||||
|
$payment = $this->gateway->payments->get($request->getPaymentId());
|
||||||
|
|
||||||
|
return (new CreditCard($this))->processSuccessfulPayment($payment);
|
||||||
|
} catch(\Mollie\Api\Exceptions\ApiException $e) {
|
||||||
|
return (new CreditCard($this))->processUnsuccessfulPayment($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user