diff --git a/app/PaymentDrivers/Braintree/ACH.php b/app/PaymentDrivers/Braintree/ACH.php new file mode 100644 index 0000000000..98ab379c3b --- /dev/null +++ b/app/PaymentDrivers/Braintree/ACH.php @@ -0,0 +1,79 @@ +braintree = $braintree; + + $this->braintree->init(); + } + + public function authorizeView(array $data) + { + $data['gateway'] = $this->braintree; + $data['client_token'] = $this->braintree->gateway->clientToken()->generate(); + + return render('gateways.braintree.ach.authorize', $data); + } + + public function authorizeResponse(Request $request) + { + $request->validate([ + 'nonce' => ['required'], + 'gateway_type_id' => ['required'], + ]); + + $customer = $this->braintree->findOrCreateCustomer(); + + $result = $this->braintree->gateway->paymentMethod()->create([ + 'customerId' => $customer->id, + 'paymentMethodNonce' => $request->nonce, + 'options' => [ + 'usBankAccountVerificationMethod' => \Braintree\Result\UsBankAccountVerification::NETWORK_CHECK, + ], + ]); + + if ($result->success) { + $account = $result->paymentMethod; + + try { + $payment_meta = new \stdClass; + $payment_meta->brand = (string)$account->bankName; + $payment_meta->last4 = (string)$account->last4; + $payment_meta->type = GatewayType::BANK_TRANSFER; + $payment_meta->state = $account->verified ? 'authorized' : 'unauthorized'; + + $data = [ + 'payment_meta' => $payment_meta, + 'token' => $account->token, + 'payment_method_id' => $request->gateway_type_id, + ]; + + $this->braintree->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]); + + return redirect()->route('client.payment_methods.index'); + } catch (\Exception $e) { + // .. + } + } + } +}