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

View File

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

View File

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

View File

@ -11,54 +11,69 @@
namespace App\PaymentDrivers\CBAPowerBoard\Models;
class Transactions
class Threeds
{
/** @var string */
public string $created_at;
/** @var int */
public int $amount;
/** @var string */
public string $currency;
/** @var string */
public string $_id;
/** @var string */
public ?string $error_code;
/** @var ?string */
public ?string $error_message;
/** @var ?string */
public ?string $gateway_specific_description;
/** @var ?string */
public function __construct(public ?string $token){}
}
class Transaction
{
public ?Threeds $_3ds;
public ?string $gateway_specific_code;
/** @var string */
public string $_source_ip_address;
/** @var string */
public string $status;
/** @var string */
public string $type;
public ?string $gateway_specific_description;
public ?string $error_message;
public ?string $error_code;
public ?string $status_code;
public ?string $status_code_description;
public ?string $type;
public ?string $status;
public float $amount;
public ?string $currency;
public ?string $_id;
public ?string $created_at;
public ?string $updated_at;
public ?string $processed_at;
public ?string $external_id;
public ?string $external_reference;
public ?string $authorization_code;
public function __construct(
string $created_at,
int $amount,
string $currency,
string $_id,
?string $error_code,
?string $error_message,
?string $gateway_specific_description,
?Threeds $_3ds,
?string $gateway_specific_code,
string $_source_ip_address,
string $status,
string $type
?string $gateway_specific_description,
?string $error_message,
?string $error_code,
?string $status_code,
?string $status_code_description,
?string $type,
?string $status,
float $amount,
?string $currency,
?string $_id,
?string $created_at,
?string $updated_at,
?string $processed_at,
?string $external_id,
?string $external_reference,
?string $authorization_code
) {
$this->created_at = $created_at;
$this->_3ds = $_3ds;
$this->gateway_specific_code = $gateway_specific_code;
$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->error_code = $error_code;
$this->error_message = $error_message;
$this->gateway_specific_description = $gateway_specific_description;
$this->gateway_specific_code = $gateway_specific_code;
$this->_source_ip_address = $_source_ip_address;
$this->status = $status;
$this->type = $type;
$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="widget" style="block"></div>
<div id="widget-3dsecure"></div>
</div>
@include('portal.ninja2020.gateways.includes.save_card')
@ -144,11 +145,20 @@
console.log("3DS Token:", resource);
console.log("pre canvas");
console.log(resource._3ds.token);
var canvas = new cba.Canvas3ds('#widget-3dsecure', resource._3ds.token);
canvas.load();
console.log("post canvas");
let widget = document.getElementById('widget');
widget.classList.add('hidden');
} catch (error) {
console.error("Error fetching 3DS Token:", error);
}
canvas.on("chargeAuthSuccess", function(data) {
console.log(data);
@ -161,7 +171,6 @@
'input[name="charge"]'
).value = JSON.stringify(data);
document.getElementById('server-response').submit();
});
@ -170,19 +179,14 @@
console.log(data);
});
} catch (error) {
console.error("Error fetching 3DS Token:", error);
}
canvas.load();
});
widget.on("submit", async function (data){
console.log("submit");
console.log(data);
})
widget.on('form_submit', function (data) {