diff --git a/app/DataMapper/PaymentMethodMeta.php b/app/DataMapper/PaymentMethodMeta.php index 3745fa299e3d..451870fd42b4 100644 --- a/app/DataMapper/PaymentMethodMeta.php +++ b/app/DataMapper/PaymentMethodMeta.php @@ -27,4 +27,7 @@ class PaymentMethodMeta /** @var int */ public $type; + + /** @var string */ + public $state; } diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index 5e554d2783d1..0f6bd432b217 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -92,9 +92,9 @@ class PaymentMethodController extends Controller public function verify(ClientGatewayToken $payment_method) { - $gateway = $this->getClientGateway(); - - return $gateway +// $gateway = $this->getClientGateway(); + + return $payment_method->gateway ->driver(auth()->user()->client) ->setPaymentMethod(request()->query('method')) ->verificationView($payment_method); @@ -102,9 +102,9 @@ class PaymentMethodController extends Controller public function processVerification(Request $request, ClientGatewaytoken $payment_method) { - $gateway = $this->getClientGateway(); + // $gateway = $this->getClientGateway(); - return $gateway + return $payment_method->gateway ->driver(auth()->user()->client) ->setPaymentMethod(request()->query('method')) ->processVerification($request, $payment_method); @@ -118,9 +118,9 @@ class PaymentMethodController extends Controller */ public function destroy(ClientGatewayToken $payment_method) { - $gateway = $this->getClientGateway(); + // $gateway = $this->getClientGateway(); - $gateway + $payment_method->gateway ->driver(auth()->user()->client) ->setPaymentMethod(request()->query('method')) ->detach($payment_method); diff --git a/app/PaymentDrivers/Stripe/ACH.php b/app/PaymentDrivers/Stripe/ACH.php index 3dfe09459170..5ee3c8602479 100644 --- a/app/PaymentDrivers/Stripe/ACH.php +++ b/app/PaymentDrivers/Stripe/ACH.php @@ -167,7 +167,7 @@ class ACH return $this->processUnsuccessfulPayment($state); } catch (Exception $e) { if ($e instanceof CardException) { - return redirect()->route('client.payment_methods.verification', ['id' => ClientGatewayToken::first()->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); + return redirect()->route('client.payment_methods.verification', ['payment_method' => ClientGatewayToken::first()->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); } throw new PaymentFailed($e->getMessage(), $e->getCode()); diff --git a/app/PaymentDrivers/WePay/ACH.php b/app/PaymentDrivers/WePay/ACH.php index 521f853b08ad..23f8cb37c37c 100644 --- a/app/PaymentDrivers/WePay/ACH.php +++ b/app/PaymentDrivers/WePay/ACH.php @@ -13,13 +13,16 @@ namespace App\PaymentDrivers\WePay; use App\Exceptions\PaymentFailed; -use Illuminate\Http\Request; use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\PaymentDrivers\WePayPaymentDriver; +use App\Utils\Traits\MakesHash; +use Illuminate\Http\Request; class ACH { + use MakesHash; + public $wepay_payment_driver; public function __construct(WePayPaymentDriver $wepay_payment_driver) @@ -115,15 +118,30 @@ class ACH */ public function processVerification(Request $request, ClientGatewayToken $token) { + $transactions = $request->input('transactions'); - $response = $this->wepay_payment_driver->wepay->request('payment_bank/verify', [ - 'client_id' => config('ninja.wepay.client_id'), - 'client_secret' => config('ninja.wepay.client_secret'), - 'payment_bank_id' => $token->token, - 'type' => 'microdeposits', - 'microdeposits' => $request->input('transactions'), - ]); + $transformed_transactions = []; + foreach($transactions as $transaction) + $transformed_transactions[] = (int)$transaction; + + try { + + $response = $this->wepay_payment_driver->wepay->request('payment_bank/verify', [ + 'client_id' => config('ninja.wepay.client_id'), + 'client_secret' => config('ninja.wepay.client_secret'), + 'payment_bank_id' => $token->token, + 'type' => 'microdeposits', + 'microdeposits' => $transformed_transactions, + ]); + + } + catch(\Exception $e){ + + return redirect()->route('client.payment_methods.verification', ['payment_method' => $token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]) + ->with('error', $e->getMessage()); + + } /* { "payment_bank_id": 12345, @@ -132,20 +150,23 @@ class ACH "state": "authorized" } */ - + nlog($response); + //$meta = $token->meta; if($response->state == "authorized") { - - $token->routing_number = $response->state; + $meta = $token->meta; + $meta->state = $response->state; + $token->meta; $token->save(); - redirect()->route('client.payment_methods.index'); + return redirect()->route('client.payment_methods.index'); } else{ - redirect()->route('client.payment_methods.verification', ['id' => $token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]) - ->withErrors(['errors', ctrans('verification_failed')]); + + return redirect()->route('client.payment_methods.verification', ['payment_method' => $token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]) + ->with('error', ctrans('texts.verification_failed')); } } @@ -166,7 +187,42 @@ class ACH { nlog($request->all()); - redirect()->route('client.payment_methods.verification', ['id' => $token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); + $token = ClientGatewayToken::find($this->decodePrimaryKey($request->input('source'))); + $token_meta = $token->meta; + + if($token_meta->state != "authorized") + return redirect()->route('client.payment_methods.verification', ['payment_method' => $token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); + + + + + + +// response = wepay.call('/checkout/create', { +// 'account_id': account_id, +// 'amount': '25.50', +// 'short_description': 'A vacation home rental', +// 'type': 'GOODS', +// 'payment_method': { +// 'type': 'payment_bank', +// 'payment_bank': { +// 'id': 20000061 +// } +// } +// }) + + + + + + + + + + + + + // $this->stripe->init(); @@ -242,12 +298,12 @@ class ACH $payment_meta->brand = (string) $response->bank_name; $payment_meta->last4 = (string) $response->account_last_four; $payment_meta->type = GatewayType::BANK_TRANSFER; + $payment_meta->state = $response->state; $data = [ 'payment_meta' => $payment_meta, 'token' => $response->payment_bank_id, 'payment_method_id' => $payment_method_id, - 'routing_number' => $response->state, ]; $this->wepay_payment_driver->storeGatewayToken($data); diff --git a/app/PaymentDrivers/WePay/CreditCard.php b/app/PaymentDrivers/WePay/CreditCard.php index e75038976648..fb5b1fe56c75 100644 --- a/app/PaymentDrivers/WePay/CreditCard.php +++ b/app/PaymentDrivers/WePay/CreditCard.php @@ -89,6 +89,34 @@ class CreditCard } + public function paymentView(array $data) + { + $data['gateway'] = $this->wepay_payment_driver; + + return render('gateways.wepay.credit_card.pay', $data); + } + + public function paymentResponse(PaymentResponseRequest $request) + { + + + // // 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 + // ) + // ) + // )); + + } + private function storePaymentMethod($response, $payment_method_id) { @@ -109,5 +137,7 @@ class CreditCard } + + } diff --git a/app/PaymentDrivers/WePayPaymentDriver.php b/app/PaymentDrivers/WePayPaymentDriver.php index 7245528a9771..de7c6caf3df9 100644 --- a/app/PaymentDrivers/WePayPaymentDriver.php +++ b/app/PaymentDrivers/WePayPaymentDriver.php @@ -134,6 +134,20 @@ class WePayPaymentDriver extends BaseDriver return $this->payment_method->authorizeResponse($request); //this is your custom implementation from here } + public function verificationView(ClientGatewayToken $cgt) + { + $this->init(); + + return $this->payment_method->verificationView($cgt); + } + + public function processVerification(Request $request, ClientGatewayToken $cgt) + { + $this->init(); + + return $this->payment_method->processVerification($request, $cgt); + } + public function processPaymentView(array $data) { return $this->payment_method->paymentView($data); //this is your custom implementation from here diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 9670fe609788..742103e460c2 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -4256,6 +4256,7 @@ $LANG = array( 'user_cross_linked_error' => 'User exists but cannot be crossed linked to multiple accounts', 'company_import_failure_subject' => 'Error importing :company', 'company_import_failure_body' => 'There was an error importing the company data, the error message was:', + 'amount_cents' => 'Amount in pennies,pence or cents' ); return $LANG; diff --git a/resources/views/portal/ninja2020/gateways/stripe/ach/verify.blade.php b/resources/views/portal/ninja2020/gateways/stripe/ach/verify.blade.php index 9cdcf2803c4e..e173a2dd84a9 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/ach/verify.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/ach/verify.blade.php @@ -10,11 +10,11 @@ - @component('portal.ninja2020.components.general.card-element', ['title' => '#1 ' . ctrans('texts.amount')]) + @component('portal.ninja2020.components.general.card-element', ['title' => '#1 ' . ctrans('texts.amount_cents')]) @endcomponent - @component('portal.ninja2020.components.general.card-element', ['title' => '#2 ' . ctrans('texts.amount')]) + @component('portal.ninja2020.components.general.card-element', ['title' => '#2 ' . ctrans('texts.amount_cents')]) @endcomponent diff --git a/resources/views/portal/ninja2020/gateways/wepay/authorize/verify.blade.php b/resources/views/portal/ninja2020/gateways/wepay/authorize/verify.blade.php index aa8328add490..8087eb3b6ce2 100644 --- a/resources/views/portal/ninja2020/gateways/wepay/authorize/verify.blade.php +++ b/resources/views/portal/ninja2020/gateways/wepay/authorize/verify.blade.php @@ -9,11 +9,11 @@ @csrf - @component('portal.ninja2020.components.general.card-element', ['title' => '#1 ' . ctrans('texts.amount')]) + @component('portal.ninja2020.components.general.card-element', ['title' => '#1 ' . ctrans('texts.amount_cents')]) @endcomponent - @component('portal.ninja2020.components.general.card-element', ['title' => '#2 ' . ctrans('texts.amount')]) + @component('portal.ninja2020.components.general.card-element', ['title' => '#2 ' . ctrans('texts.amount_cents')]) @endcomponent diff --git a/resources/views/portal/ninja2020/gateways/wepay/bank_transfer.blade.php b/resources/views/portal/ninja2020/gateways/wepay/bank_transfer.blade.php index 0d38a0a16fe2..3c77a2519dfa 100644 --- a/resources/views/portal/ninja2020/gateways/wepay/bank_transfer.blade.php +++ b/resources/views/portal/ninja2020/gateways/wepay/bank_transfer.blade.php @@ -43,5 +43,15 @@ @endsection @push('footer') + @endpush 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 new file mode 100644 index 000000000000..e69de29bb2d1