From caf5a615d3052d30475f6ace053e8719c9a5f7b8 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 19 Aug 2022 13:45:21 +0700 Subject: [PATCH] Fix default customer object --- modules/gateways/xendit/lib/CreditCard.php | 5 ++++- modules/gateways/xendit/lib/Link.php | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/gateways/xendit/lib/CreditCard.php b/modules/gateways/xendit/lib/CreditCard.php index a539ff3..f997132 100644 --- a/modules/gateways/xendit/lib/CreditCard.php +++ b/modules/gateways/xendit/lib/CreditCard.php @@ -85,6 +85,7 @@ public function generateCCPaymentRequest(array $params = [], int $auth_id = null throw new \Exception("Invoice does not exist"); } + $billingDetailObject = $this->extractCustomer($params['clientdetails'], true); $payload = [ "amount" => $this->roundUpTotal($params["amount"]), "currency" => $params["currency"], @@ -92,11 +93,13 @@ public function generateCCPaymentRequest(array $params = [], int $auth_id = null "external_id" => $this->generateExternalId($params["invoiceid"], true), "store_name" => $params["companyname"], "items" => $this->extractItems($invoice), - "billing_details" => $this->extractCustomer($params['clientdetails'], true), "is_recurring" => true, "should_charge_multiple_use_token" => true ]; + if(!empty($billingDetailObject)){ + $payload['billing_details'] = $billingDetailObject; + } if (!empty($auth_id)) { $payload["authentication_id"] = $auth_id; } diff --git a/modules/gateways/xendit/lib/Link.php b/modules/gateways/xendit/lib/Link.php index f5d8b05..f55bba7 100644 --- a/modules/gateways/xendit/lib/Link.php +++ b/modules/gateways/xendit/lib/Link.php @@ -17,7 +17,7 @@ class Link extends ActionBase protected function generateInvoicePayload(array $params, bool $retry = false): array { $invoice = $this->getInvoice($params["invoiceid"]); - + $customerObject = $this->extractCustomer($params['clientdetails']); $payload = [ 'external_id' => $this->generateExternalId($params["invoiceid"], $retry), 'payer_email' => $params['clientdetails']['email'], @@ -29,10 +29,13 @@ protected function generateInvoicePayload(array $params, bool $retry = false): a 'platform_callback_url' => $params["systemurl"] . $this->callbackUrl, 'success_redirect_url' => $this->invoiceUrl($params['invoiceid'], $params['systemurl']), 'failure_redirect_url' => $this->invoiceUrl($params['invoiceid'], $params['systemurl']), - 'should_charge_multiple_use_token' => true, - 'customer' => $this->extractCustomer($params['clientdetails']) + 'should_charge_multiple_use_token' => true ]; + if(!empty($customerObject)){ + $payload['customer'] = $customerObject; + } + // Only add the payment fee if it's > 0 if ($params['paymentfee'] > 0) { $payload["fees"] = array(['type' => 'Payment Fee', 'value' => (float)$params['paymentfee']]);