diff --git a/app/PaymentDrivers/CBAPowerBoard/CreditCard.php b/app/PaymentDrivers/CBAPowerBoard/CreditCard.php index c9c37eb70c62..b28b3b3bd2a7 100644 --- a/app/PaymentDrivers/CBAPowerBoard/CreditCard.php +++ b/app/PaymentDrivers/CBAPowerBoard/CreditCard.php @@ -73,7 +73,7 @@ class CreditCard implements LivewireMethodInterface $payload = array_merge($this->getCustomer(), [ 'token' => $payment_source, - "vault_type" => "session", + "vault_type" => "permanent", 'store_ccv' => true, ]); @@ -165,7 +165,9 @@ class CreditCard implements LivewireMethodInterface public function paymentResponse(PaymentResponseRequest $request) { 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; $payload = []; @@ -192,20 +194,22 @@ class CreditCard implements LivewireMethodInterface { $payment_source = $this->storePaymentSource($request); + nlog($payment_source); + return $this->get3dsToken($payment_source, $request); } elseif($request->charge) { $charge_request = json_decode($request->charge, true); - + nlog("we have the charge request"); nlog($charge_request); $payload = [ '_3ds' => [ '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, "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(); + nlog($charge); + if ($charge->status == 'complete') { $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); } } - - - 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) diff --git a/app/PaymentDrivers/CBAPowerBoard/Customer.php b/app/PaymentDrivers/CBAPowerBoard/Customer.php index 8020401dbdaa..9062f122d1ef 100644 --- a/app/PaymentDrivers/CBAPowerBoard/Customer.php +++ b/app/PaymentDrivers/CBAPowerBoard/Customer.php @@ -105,8 +105,6 @@ class Customer if($r->failed()) $r->throw(); - // $this->storePaymentMethod($r->object()); - return (new \App\PaymentDrivers\CBAPowerBoard\Models\Parse())->encode(ModelsCustomer::class, $r->object()->resource->data) ?? $r->throw(); } diff --git a/app/PaymentDrivers/CBAPowerBoard/Models/Customer.php b/app/PaymentDrivers/CBAPowerBoard/Models/Customer.php index b6b52ded3948..a207b79ec719 100644 --- a/app/PaymentDrivers/CBAPowerBoard/Models/Customer.php +++ b/app/PaymentDrivers/CBAPowerBoard/Models/Customer.php @@ -40,6 +40,8 @@ class Customer public ?bool $_check_expire_date; /** @var ?PaymentSource[] */ public ?array $payment_sources; + /** @var ?PaymentSource */ + public ?PaymentSource $payment_source; /** @var ?array */ public ?array $payment_destinations; /** @var ?string */ @@ -60,7 +62,8 @@ class Customer ?bool $_check_expire_date, ?array $payment_sources, ?array $payment_destinations, - ?string $company_id + ?string $company_id, + ?PaymentSource $payment_source ) { $this->_id = $_id; $this->_source_ip_address = $_source_ip_address; @@ -77,5 +80,6 @@ class Customer $this->payment_sources = $payment_sources; $this->payment_destinations = $payment_destinations; $this->company_id = $company_id; + $this->payment_source = $payment_source; } } \ No newline at end of file diff --git a/app/PaymentDrivers/CBAPowerBoard/Models/PaymentSource.php b/app/PaymentDrivers/CBAPowerBoard/Models/PaymentSource.php index 5d9f27e0fa5b..019b2fcfa9d0 100644 --- a/app/PaymentDrivers/CBAPowerBoard/Models/PaymentSource.php +++ b/app/PaymentDrivers/CBAPowerBoard/Models/PaymentSource.php @@ -41,14 +41,14 @@ class PaymentSource public int $expire_month; /** @var int */ public int $expire_year; - /** @var string */ - public string $status; - /** @var string */ - public string $created_at; - /** @var string */ - public string $updated_at; - /** @var string */ - public string $vault_type; + /** @var ?string */ + public ?string $status; + /** @var ?string */ + public ?string $created_at; + /** @var ?string */ + public ?string $updated_at; + /** @var ?string */ + public ?string $vault_type; /** @var ?string */ public ?string $gateway_id; @@ -67,10 +67,10 @@ class PaymentSource ?string $address_state, int $expire_month, int $expire_year, - string $status, - string $created_at, - string $updated_at, - string $vault_type, + ?string $status, + ?string $created_at, + ?string $updated_at, + ?string $vault_type, ?string $gateway_id ) { $this->_id = $_id; diff --git a/resources/views/portal/ninja2020/gateways/powerboard/credit_card/pay.blade.php b/resources/views/portal/ninja2020/gateways/powerboard/credit_card/pay.blade.php index 9f1cd1fdfb97..b0efe090491e 100644 --- a/resources/views/portal/ninja2020/gateways/powerboard/credit_card/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/powerboard/credit_card/pay.blade.php @@ -171,6 +171,14 @@ 'input[name="charge"]' ).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(); });