Payment with 3ds

This commit is contained in:
David Bomba 2024-09-08 19:52:39 +10:00
parent 1f3c37a76b
commit 590616a780
5 changed files with 193 additions and 176 deletions

View File

@ -165,7 +165,7 @@ class CreditCard implements LivewireMethodInterface
public function paymentResponse(PaymentResponseRequest $request) public function paymentResponse(PaymentResponseRequest $request)
{ {
nlog($request->all()); nlog($request->all());
$payment_hash = PaymentHash::where('hash', $request->payment_has)->first(); $payment_hash = PaymentHash::where('hash', $request->payment_hash)->first();
// $token = $request->payment_source; // $token = $request->payment_source;
$payload = []; $payload = [];
@ -197,22 +197,26 @@ class CreditCard implements LivewireMethodInterface
} }
elseif($request->charge) { elseif($request->charge) {
$charge_request = json_decode($request->charge, true);
nlog($charge_request);
$payload = [ $payload = [
'3ds' => [ '_3ds' => [
'id' => $request['charge']['charge_3ds_id'], 'id' => $charge_request['charge_3ds_id'],
], ],
"amount"=> $payment_hash->data->amount_with_fee, "amount"=> $payment_hash->data->amount_with_fee,
"currency"=> $this->powerboard->client->currency()->code, "currency"=> $this->powerboard->client->currency()->code,
"store_cvv"=> true, "store_cvv"=> true,
]; ];
nlog($payload);
$r = $this->powerboard->gatewayRequest("/v1/charges", (\App\Enum\HttpVerb::POST)->value, $payload, []); $r = $this->powerboard->gatewayRequest("/v1/charges", (\App\Enum\HttpVerb::POST)->value, $payload, []);
if($r->failed()) if($r->failed())
$r->throw(); $r->throw();
$charge = (new \App\PaymentDrivers\CBAPowerBoard\Models\Parse())->encode(Charge::class, $r->object()->resource->data) ?? $r->throw(); $charge = (new \App\PaymentDrivers\CBAPowerBoard\Models\Parse())->encode(Charge::class, $r->object()->resource->data) ?? $r->throw();
if ($charge->status == 'complete') { if ($charge->status == 'complete') {
@ -273,7 +277,7 @@ class CreditCard implements LivewireMethodInterface
$payment = $this->powerboard->createPayment($data, Payment::STATUS_COMPLETED); $payment = $this->powerboard->createPayment($data, Payment::STATUS_COMPLETED);
SystemLogger::dispatch( SystemLogger::dispatch(
['response' => $this->powerboard->payment_hash->data->server_response, 'data' => $data], ['response' => $charge, 'data' => $data],
SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::EVENT_GATEWAY_SUCCESS,
SystemLog::TYPE_POWERBOARD, SystemLog::TYPE_POWERBOARD,

View File

@ -13,59 +13,56 @@ namespace App\PaymentDrivers\CBAPowerBoard\Models;
class Charge class Charge
{ {
/** @var string */ /** @var ?string */
public string $external_id; public ?string $external_id;
/** @var string */ /** @var ?string */
public string $_id; public ?string $_id;
/** @var string */ /** @var ?string */
public string $created_at; public ?string $created_at;
/** @var string */ /** @var ?string */
public string $updated_at; public ?string $updated_at;
/** @var string */ /** @var ?string */
public string $remittance_date; public ?string $remittance_date;
/** @var string */ /** @var ?string */
public string $company_id; public ?string $company_id;
/** @var int */ /** @var float */
public int $amount; public float $amount;
/** @var string */ /** @var ?string */
public string $currency; public ?string $currency;
/** @var int */ /** @var ?int */
public int $__v; public ?int $__v;
/** @var Transactions[] */ /** @var Transaction[] */
public array $transactions; public array $transactions;
/** @var bool */ /** @var ?bool */
public bool $one_off; public ?bool $one_off;
/** @var bool */ /** @var ?bool */
public bool $archived; public ?bool $archived;
/** @var Customer */ /** @var Customer */
public Customer $customer; public Customer $customer;
/** @var bool */ /** @var ?bool */
public bool $capture; public ?bool $capture;
/** @var string */ /** @var ?string */
public string $status; public? string $status;
/** @var array */ /** @var ?array */
public array $items; public ?array $items;
/**
* @param Transactions[] $transactions
*/
public function __construct( public function __construct(
string $external_id, ?string $external_id,
string $_id, ?string $_id,
string $created_at, ?string $created_at,
string $updated_at, ?string $updated_at,
string $remittance_date, ?string $remittance_date,
string $company_id, ?string $company_id,
int $amount, float $amount,
string $currency, ?string $currency,
int $__v, ?int $__v,
array $transactions, array $transactions,
bool $one_off, ?bool $one_off,
bool $archived, ?bool $archived,
Customer $customer, Customer $customer,
bool $capture, ?bool $capture,
string $status, ?string $status,
array $items, ?array $items,
) { ) {
$this->external_id = $external_id; $this->external_id = $external_id;
$this->_id = $_id; $this->_id = $_id;

View File

@ -14,56 +14,53 @@ namespace App\PaymentDrivers\CBAPowerBoard\Models;
class Customer class Customer
{ {
/** @var string */ /** @var ?string */
public string $_id; public ?string $_id;
/** @var string */ /** @var ?string */
public string $_source_ip_address; public ?string $_source_ip_address;
/** @var string */ /** @var ?string */
public string $first_name; public ?string $first_name;
/** @var string */ /** @var ?string */
public string $last_name; public ?string $last_name;
/** @var string */ /** @var ?string */
public string $email; public ?string $email;
/** @var string */ /** @var ?string */
public string $reference; public ?string $reference;
/** @var string */ /** @var ?string */
public string $default_source; public ?string $default_source;
/** @var string */ /** @var ?string */
public string $status; public ?string $status;
/** @var bool */ /** @var ?bool */
public bool $archived; public ?bool $archived;
/** @var string */ /** @var ?string */
public string $created_at; public ?string $created_at;
/** @var string */ /** @var ?string */
public string $updated_at; public ?string $updated_at;
/** @var bool */ /** @var ?bool */
public bool $_check_expire_date; public ?bool $_check_expire_date;
/** @var PaymentSource[] */ /** @var ?PaymentSource[] */
public array $payment_sources; public ?array $payment_sources;
/** @var array */ /** @var ?array */
public array $payment_destinations; public ?array $payment_destinations;
/** @var string */ /** @var ?string */
public string $company_id; public ?string $company_id;
/**
* @param PaymentSource[] $payment_sources
*/
public function __construct( public function __construct(
string $_id, ?string $_id,
string $_source_ip_address, ?string $_source_ip_address,
string $first_name, ?string $first_name,
string $last_name, ?string $last_name,
string $email, ?string $email,
string $reference, ?string $reference,
string $default_source, ?string $default_source,
string $status, ?string $status,
bool $archived, ?bool $archived,
string $created_at, ?string $created_at,
string $updated_at, ?string $updated_at,
bool $_check_expire_date, ?bool $_check_expire_date,
array $payment_sources, ?array $payment_sources,
array $payment_destinations, ?array $payment_destinations,
string $company_id ?string $company_id
) { ) {
$this->_id = $_id; $this->_id = $_id;
$this->_source_ip_address = $_source_ip_address; $this->_source_ip_address = $_source_ip_address;

View File

@ -11,54 +11,69 @@
namespace App\PaymentDrivers\CBAPowerBoard\Models; namespace App\PaymentDrivers\CBAPowerBoard\Models;
class Transactions class Threeds
{ {
/** @var string */ public function __construct(public ?string $token){}
public string $created_at; }
/** @var int */
public int $amount; class Transaction
/** @var string */ {
public string $currency; public ?Threeds $_3ds;
/** @var string */ public ?string $gateway_specific_code;
public string $_id; public ?string $gateway_specific_description;
/** @var string */ public ?string $error_message;
public ?string $error_code; public ?string $error_code;
/** @var ?string */ public ?string $status_code;
public ?string $error_message; public ?string $status_code_description;
/** @var ?string */ public ?string $type;
public ?string $gateway_specific_description; public ?string $status;
/** @var ?string */ public float $amount;
public ?string $gateway_specific_code; public ?string $currency;
/** @var string */ public ?string $_id;
public string $_source_ip_address; public ?string $created_at;
/** @var string */ public ?string $updated_at;
public string $status; public ?string $processed_at;
/** @var string */ public ?string $external_id;
public string $type; public ?string $external_reference;
public ?string $authorization_code;
public function __construct(
string $created_at, public function __construct(
int $amount, ?Threeds $_3ds,
string $currency, ?string $gateway_specific_code,
string $_id, ?string $gateway_specific_description,
?string $error_code, ?string $error_message,
?string $error_message, ?string $error_code,
?string $gateway_specific_description, ?string $status_code,
?string $gateway_specific_code, ?string $status_code_description,
string $_source_ip_address, ?string $type,
string $status, ?string $status,
string $type float $amount,
) { ?string $currency,
$this->created_at = $created_at; ?string $_id,
$this->amount = $amount; ?string $created_at,
$this->currency = $currency; ?string $updated_at,
$this->_id = $_id; ?string $processed_at,
$this->error_code = $error_code; ?string $external_id,
$this->error_message = $error_message; ?string $external_reference,
$this->gateway_specific_description = $gateway_specific_description; ?string $authorization_code
$this->gateway_specific_code = $gateway_specific_code; ) {
$this->_source_ip_address = $_source_ip_address; $this->_3ds = $_3ds;
$this->status = $status; $this->gateway_specific_code = $gateway_specific_code;
$this->type = $type; $this->gateway_specific_description = $gateway_specific_description;
} $this->error_message = $error_message;
$this->error_code = $error_code;
$this->status_code = $status_code;
$this->status_code_description = $status_code_description;
$this->type = $type;
$this->status = $status;
$this->amount = $amount;
$this->currency = $currency;
$this->_id = $_id;
$this->created_at = $created_at;
$this->updated_at = $updated_at;
$this->processed_at = $processed_at;
$this->external_id = $external_id;
$this->external_reference = $external_reference;
$this->authorization_code = $authorization_code;
}
} }

View File

@ -64,6 +64,7 @@
<div id="powerboard-payment-container" class="w-full"> <div id="powerboard-payment-container" class="w-full">
<div id="widget" style="block"></div> <div id="widget" style="block"></div>
<div id="widget-3dsecure"></div>
</div> </div>
@include('portal.ninja2020.gateways.includes.save_card') @include('portal.ninja2020.gateways.includes.save_card')
@ -144,45 +145,48 @@
console.log("3DS Token:", resource); console.log("3DS Token:", resource);
console.log("pre canvas"); console.log("pre canvas");
console.log(resource._3ds.token);
var canvas = new cba.Canvas3ds('#widget-3dsecure', resource._3ds.token); var canvas = new cba.Canvas3ds('#widget-3dsecure', resource._3ds.token);
canvas.load(); canvas.load();
console.log("post canvas"); let widget = document.getElementById('widget');
widget.classList.add('hidden');
canvas.on("chargeAuthSuccess", function(data) {
console.log(data);
document.querySelector(
'input[name="browser_details"]'
).value = null;
document.querySelector(
'input[name="charge"]'
).value = JSON.stringify(data);
document.getElementById('server-response').submit();
});
canvas.on("chargeAuthReject", function(data) {
console.log(data);
});
} catch (error) { } catch (error) {
console.error("Error fetching 3DS Token:", error); console.error("Error fetching 3DS Token:", error);
} }
canvas.on("chargeAuthSuccess", function(data) {
console.log(data);
document.querySelector(
'input[name="browser_details"]'
).value = null;
document.querySelector(
'input[name="charge"]'
).value = JSON.stringify(data);
document.getElementById('server-response').submit();
});
canvas.on("chargeAuthReject", function(data) {
console.log(data);
});
canvas.load();
}); });
widget.on("submit", async function (data){ widget.on("submit", async function (data){
console.log("submit"); console.log("submit");
console.log(data); console.log(data);
}) })
widget.on('form_submit', function (data) { widget.on('form_submit', function (data) {