3ds payment flow

This commit is contained in:
David Bomba 2024-09-09 15:52:11 +10:00
parent 590616a780
commit 2e114692e7
5 changed files with 51 additions and 54 deletions

View File

@ -73,7 +73,7 @@ class CreditCard implements LivewireMethodInterface
$payload = array_merge($this->getCustomer(), [ $payload = array_merge($this->getCustomer(), [
'token' => $payment_source, 'token' => $payment_source,
"vault_type" => "session", "vault_type" => "permanent",
'store_ccv' => true, 'store_ccv' => true,
]); ]);
@ -165,7 +165,9 @@ 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_hash)->first(); $this->powerboard->payment_hash->data = array_merge((array) $this->powerboard->payment_hash->data, ['response' => $request->all()]);
$this->powerboard->payment_hash->save();
// $token = $request->payment_source; // $token = $request->payment_source;
$payload = []; $payload = [];
@ -192,20 +194,22 @@ class CreditCard implements LivewireMethodInterface
{ {
$payment_source = $this->storePaymentSource($request); $payment_source = $this->storePaymentSource($request);
nlog($payment_source);
return $this->get3dsToken($payment_source, $request); return $this->get3dsToken($payment_source, $request);
} }
elseif($request->charge) { elseif($request->charge) {
$charge_request = json_decode($request->charge, true); $charge_request = json_decode($request->charge, true);
nlog("we have the charge request");
nlog($charge_request); nlog($charge_request);
$payload = [ $payload = [
'_3ds' => [ '_3ds' => [
'id' => $charge_request['charge_3ds_id'], 'id' => $charge_request['charge_3ds_id'],
], ],
"amount"=> $payment_hash->data->amount_with_fee, "amount"=> $this->powerboard->payment_hash->data->amount_with_fee,
"currency"=> $this->powerboard->client->currency()->code, "currency"=> $this->powerboard->client->currency()->code,
"store_cvv"=> true, "store_cvv"=> true,
]; ];
@ -219,49 +223,32 @@ class CreditCard implements LivewireMethodInterface
$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();
nlog($charge);
if ($charge->status == 'complete') { if ($charge->status == 'complete') {
$this->powerboard->logSuccessfulGatewayResponse(['response' => $charge, 'data' => $this->powerboard->payment_hash], SystemLog::TYPE_POWERBOARD); $this->powerboard->logSuccessfulGatewayResponse(['response' => $charge, 'data' => $this->powerboard->payment_hash], SystemLog::TYPE_POWERBOARD);
$vt = $charge->customer->payment_source->vault_token;
// nlog($this->powerboard->payment_hash->data);
// $vt = $r->object()->resource->data->_3ds->id;
if($request->store_card){
$data = [
"payment_source" => [
"vault_token" => $vt,
],
];
$customer = $this->powerboard->customer()->findOrCreateCustomer($data);
}
return $this->processSuccessfulPayment($charge); return $this->processSuccessfulPayment($charge);
} }
} }
nlog($request->all());
// else {
// $payload["customer"] = [
// "payment_source" => [
// "vault_token" => $cgt->token,
// "gateway_id" => $cgt->meta->gateway_id
// ]
// ];
// }
// $uri = '/v1/charges';
// $payload_meta = [
// "amount" => $payment_hash->data->amount_with_fee,
// "currency" => $this->powerboard->client->currency()->code,
// "description" => $this->powerboard->getDescription(),
// ];
// $payload = array_merge($payload, $payload_meta);
// nlog($payload);
// $r = $this->powerboard->gatewayRequest($uri, (\App\Enum\HttpVerb::POST)->value, $payload, []);
// if($r->failed())
// $r->throw();
// nlog($r->object());
// return $this->processUnsuccessfulPayment($r->body());
} }
public function processSuccessfulPayment(Charge $charge) public function processSuccessfulPayment(Charge $charge)

View File

@ -105,8 +105,6 @@ class Customer
if($r->failed()) if($r->failed())
$r->throw(); $r->throw();
// $this->storePaymentMethod($r->object());
return (new \App\PaymentDrivers\CBAPowerBoard\Models\Parse())->encode(ModelsCustomer::class, $r->object()->resource->data) ?? $r->throw(); return (new \App\PaymentDrivers\CBAPowerBoard\Models\Parse())->encode(ModelsCustomer::class, $r->object()->resource->data) ?? $r->throw();
} }

View File

@ -40,6 +40,8 @@ class Customer
public ?bool $_check_expire_date; public ?bool $_check_expire_date;
/** @var ?PaymentSource[] */ /** @var ?PaymentSource[] */
public ?array $payment_sources; public ?array $payment_sources;
/** @var ?PaymentSource */
public ?PaymentSource $payment_source;
/** @var ?array */ /** @var ?array */
public ?array $payment_destinations; public ?array $payment_destinations;
/** @var ?string */ /** @var ?string */
@ -60,7 +62,8 @@ class Customer
?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,
?PaymentSource $payment_source
) { ) {
$this->_id = $_id; $this->_id = $_id;
$this->_source_ip_address = $_source_ip_address; $this->_source_ip_address = $_source_ip_address;
@ -77,5 +80,6 @@ class Customer
$this->payment_sources = $payment_sources; $this->payment_sources = $payment_sources;
$this->payment_destinations = $payment_destinations; $this->payment_destinations = $payment_destinations;
$this->company_id = $company_id; $this->company_id = $company_id;
$this->payment_source = $payment_source;
} }
} }

View File

@ -41,14 +41,14 @@ class PaymentSource
public int $expire_month; public int $expire_month;
/** @var int */ /** @var int */
public int $expire_year; public int $expire_year;
/** @var string */ /** @var ?string */
public string $status; public ?string $status;
/** @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 $vault_type; public ?string $vault_type;
/** @var ?string */ /** @var ?string */
public ?string $gateway_id; public ?string $gateway_id;
@ -67,10 +67,10 @@ class PaymentSource
?string $address_state, ?string $address_state,
int $expire_month, int $expire_month,
int $expire_year, int $expire_year,
string $status, ?string $status,
string $created_at, ?string $created_at,
string $updated_at, ?string $updated_at,
string $vault_type, ?string $vault_type,
?string $gateway_id ?string $gateway_id
) { ) {
$this->_id = $_id; $this->_id = $_id;

View File

@ -171,6 +171,14 @@
'input[name="charge"]' 'input[name="charge"]'
).value = JSON.stringify(data); ).value = JSON.stringify(data);
let storeCard = document.querySelector(
'input[name=token-billing-checkbox]:checked'
);
if (storeCard) {
document.getElementById('store_card').value = storeCard.value;
}
document.getElementById('server-response').submit(); document.getElementById('server-response').submit();
}); });