From d90b8849226adaa298feab79b606f1efc000ed87 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 19 Jun 2021 14:58:45 +1000 Subject: [PATCH] WePay process credit/card --- app/PaymentDrivers/WePay/CreditCard.php | 88 +++++++++++++++---- .../gateways/wepay/credit_card/pay.blade.php | 32 +++---- 2 files changed, 88 insertions(+), 32 deletions(-) diff --git a/app/PaymentDrivers/WePay/CreditCard.php b/app/PaymentDrivers/WePay/CreditCard.php index b88da429fa89..b3249cf5e647 100644 --- a/app/PaymentDrivers/WePay/CreditCard.php +++ b/app/PaymentDrivers/WePay/CreditCard.php @@ -13,6 +13,7 @@ namespace App\PaymentDrivers\WePay; use App\Exceptions\PaymentFailed; +use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Models\GatewayType; use App\PaymentDrivers\WePayPaymentDriver; @@ -98,25 +99,80 @@ class CreditCard public function paymentResponse(PaymentResponseRequest $request) { - -nlog($request->all()); - // // charge the credit card - // $response = $wepay->request('checkout/create', array( - // 'account_id' => $account_id, - // 'amount' => '25.50', - // 'currency' => 'USD', - // 'short_description' => 'A vacation home rental', - // 'type' => 'goods', - // 'payment_method' => array( - // 'type' => 'credit_card', - // 'credit_card' => array( - // 'id' => $credit_card_id - // ) - // ) - // )); + // USD, CAD, and GBP. + nlog($request->all()); + // charge the credit card + $response = $this->wepay_payment_driver->wepay->request('checkout/create', array( + 'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'), + 'amount' => $this->wepay_payment_driver->payment_hash->data->amount_with_fee, + 'currency' => $this->wepay_payment_driver->client->getCurrencyCode(), + 'short_description' => 'A vacation home rental', + 'type' => 'goods', + 'payment_method' => array( + 'type' => 'credit_card', + 'credit_card' => array( + 'id' => $data['token'] + ) + ) + )); } +/* +https://developer.wepay.com/api/api-calls/checkout +{ + "checkout_id": 649945633, + "account_id": 1548718026, + "type": "donation", + "short_description": "test checkout", + "currency": "USD", + "amount": 20, + "state": "authorized", + "soft_descriptor": "WPY*Wolverine", + "auto_release": true, + "create_time": 1463589958, + "gross": 20.88, + "reference_id": null, + "callback_uri": null, + "long_description": null, + "delivery_type": null, + "initiated_by": "merchant", + "in_review": false, + "fee": { + "app_fee": 0, + "processing_fee": 0.88, + "fee_payer": "payer" + }, + "chargeback": { + "amount_charged_back": 0, + "dispute_uri": null + }, + "refund": { + "amount_refunded": 0, + "refund_reason": null + }, + "payment_method": { + "type": "credit_card", + "credit_card": { + "id": 1684847614, + "data": { + "emv_receipt": null, + "signature_url": null + }, + "auto_release": false + } + }, + "hosted_checkout": null, + "payer": { + "email": "test@example.com", + "name": "Mr Smith", + "home_address": null + }, + "npo_information": null, + "payment_error": null +} + */ + private function storePaymentMethod($response, $payment_method_id) { diff --git a/resources/views/portal/ninja2020/gateways/wepay/credit_card/pay.blade.php b/resources/views/portal/ninja2020/gateways/wepay/credit_card/pay.blade.php index ad470d9d3cf8..99ada5117688 100644 --- a/resources/views/portal/ninja2020/gateways/wepay/credit_card/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/wepay/credit_card/pay.blade.php @@ -10,13 +10,13 @@
@csrf - + - +
@@ -114,14 +114,6 @@ } /* handle the switch between token and cc */ - /* Attach store card value to form */ - let storeCard = document.querySelector('input[name=token-billing-checkbox]:checked'); - - if (storeCard) { - document.getElementById("store_card").value = storeCard.value; - } - /* Attach store card value to form */ - /* Pay Now Button */ let payNowButton = document.getElementById('pay-now'); @@ -130,8 +122,16 @@ .addEventListener('click', (e) => { let token = document.getElementById('token').value; + /* Attach store card value to form */ + let storeCard = document.querySelector('input[name=token-billing-checkbox]:checked'); + + if (storeCard) { + document.getElementById("store_card").value = storeCard.value; + } + /* Attach store card value to form */ + if(token){ - handleTokenPayment($token) + handleTokenPayment(token) } else{ handleCardPayment(); @@ -144,11 +144,11 @@ - function handleTokenPayment($token) + function handleTokenPayment(token) { - document.querySelector('input[name="credit_card_id"]').value = token; - document.getElementById('server_response').submit(); + document.querySelector('input[name="token"]').value = token; + document.getElementById('server-response').submit(); } @@ -230,8 +230,8 @@ var token = data.credit_card_id; - document.querySelector('input[name="credit_card_id"]').value = token; - document.getElementById('server_response').submit(); + document.querySelector('input[name="token"]').value = token; + document.getElementById('server-response').submit(); } });