Wepay Payments

This commit is contained in:
David Bomba 2021-06-16 20:12:04 +10:00
parent 43ff685543
commit c076998366
11 changed files with 142 additions and 28 deletions

View File

@ -27,4 +27,7 @@ class PaymentMethodMeta
/** @var int */
public $type;
/** @var string */
public $state;
}

View File

@ -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);

View File

@ -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());

View File

@ -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);

View File

@ -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
}
}

View File

@ -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

View File

@ -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;

View File

@ -10,11 +10,11 @@
<input type="hidden" name="customer" value="{{ $token->gateway_customer_reference }}">
<input type="hidden" name="source" value="{{ $token->token }}">
@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')])
<input type="text" name="transactions[]" class="w-full input" required data-cy="verification-1st">
@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')])
<input type="text" name="transactions[]" class="w-full input" required data-cy="verification-2nd">
@endcomponent

View File

@ -9,11 +9,11 @@
@csrf
<input type="hidden" name="token" value="{{ $token->token }}">
@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')])
<input type="text" name="transactions[]" class="w-full input" required data-cy="verification-1st">
@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')])
<input type="text" name="transactions[]" class="w-full input" required data-cy="verification-2nd">
@endcomponent

View File

@ -43,5 +43,15 @@
@endsection
@push('footer')
<script>
Array
.from(document.getElementsByClassName('toggle-payment-with-token'))
.forEach((element) => element.addEventListener('click', (element) => {
document.querySelector('input[name=source]').value = element.target.dataset.token;
}));
document.getElementById('pay-now').addEventListener('click', function () {
document.getElementById('server-response').submit();
});
</script>
@endpush