From ba7ea8bbea28c34e1901c5de017033e9a5c9a3cc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Aug 2021 16:00:21 +1000 Subject: [PATCH] WePay token billing --- app/PaymentDrivers/WePay/ACH.php | 6 ++++-- app/PaymentDrivers/WePay/CreditCard.php | 7 +++++-- app/PaymentDrivers/WePayPaymentDriver.php | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/PaymentDrivers/WePay/ACH.php b/app/PaymentDrivers/WePay/ACH.php index f6030a1655cf..6de6498c2ea0 100644 --- a/app/PaymentDrivers/WePay/ACH.php +++ b/app/PaymentDrivers/WePay/ACH.php @@ -281,12 +281,14 @@ class ACH if(!property_exists($token_meta, 'state') || $token_meta->state != "authorized") return redirect()->route('client.payment_methods.verification', ['payment_method' => $token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); - $app_fee = (config('ninja.wepay.fee_ach_multiplier') * $this->wepay_payment_driver->payment_hash->data->amount_with_fee) + config('ninja.wepay.fee_fixed'); + $amount = array_sum(array_column($this->wepay_payment_driver->payment_hash->invoices(), 'amount')) + $this->wepay_payment_driver->payment_hash->fee_total; + + $app_fee = (config('ninja.wepay.fee_cc_multiplier') * $amount) + config('ninja.wepay.fee_fixed'); $response = $this->wepay_payment_driver->wepay->request('checkout/create', array( 'unique_id' => Str::random(40), 'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'), - 'amount' => $this->wepay_payment_driver->payment_hash->data->amount_with_fee, + 'amount' => $amount, 'currency' => $this->wepay_payment_driver->client->getCurrencyCode(), 'short_description' => 'Goods and Services', 'type' => 'goods', diff --git a/app/PaymentDrivers/WePay/CreditCard.php b/app/PaymentDrivers/WePay/CreditCard.php index 0b5ac2088e81..5cb3567976b0 100644 --- a/app/PaymentDrivers/WePay/CreditCard.php +++ b/app/PaymentDrivers/WePay/CreditCard.php @@ -285,12 +285,15 @@ https://developer.wepay.com/api/api-calls/checkout public function tokenBilling($cgt, $payment_hash) { - $app_fee = (config('ninja.wepay.fee_cc_multiplier') * $this->wepay_payment_driver->payment_hash->data->amount_with_fee) + config('ninja.wepay.fee_fixed'); + $amount = array_sum(array_column($this->wepay_payment_driver->payment_hash->invoices(), 'amount')) + $this->wepay_payment_driver->payment_hash->fee_total; + + + $app_fee = (config('ninja.wepay.fee_cc_multiplier') * $amount) + config('ninja.wepay.fee_fixed'); // charge the credit card $response = $this->wepay_payment_driver->wepay->request('checkout/create', array( 'unique_id' => Str::random(40), 'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'), - 'amount' => $this->wepay_payment_driver->payment_hash->data->amount_with_fee, + 'amount' => $amount, 'currency' => $this->wepay_payment_driver->client->getCurrencyCode(), 'short_description' => 'Goods and services', 'type' => 'goods', diff --git a/app/PaymentDrivers/WePayPaymentDriver.php b/app/PaymentDrivers/WePayPaymentDriver.php index 32d20cbbcdd9..27c60e570b84 100644 --- a/app/PaymentDrivers/WePayPaymentDriver.php +++ b/app/PaymentDrivers/WePayPaymentDriver.php @@ -159,6 +159,7 @@ class WePayPaymentDriver extends BaseDriver public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) { + $this->init(); $this->setPaymentMethod($cgt->gateway_type_id); $this->setPaymentHash($payment_hash);