mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Wepay Payments
This commit is contained in:
parent
43ff685543
commit
c076998366
@ -27,4 +27,7 @@ class PaymentMethodMeta
|
|||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public $type;
|
public $type;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
public $state;
|
||||||
}
|
}
|
||||||
|
@ -92,9 +92,9 @@ class PaymentMethodController extends Controller
|
|||||||
|
|
||||||
public function verify(ClientGatewayToken $payment_method)
|
public function verify(ClientGatewayToken $payment_method)
|
||||||
{
|
{
|
||||||
$gateway = $this->getClientGateway();
|
// $gateway = $this->getClientGateway();
|
||||||
|
|
||||||
return $gateway
|
return $payment_method->gateway
|
||||||
->driver(auth()->user()->client)
|
->driver(auth()->user()->client)
|
||||||
->setPaymentMethod(request()->query('method'))
|
->setPaymentMethod(request()->query('method'))
|
||||||
->verificationView($payment_method);
|
->verificationView($payment_method);
|
||||||
@ -102,9 +102,9 @@ class PaymentMethodController extends Controller
|
|||||||
|
|
||||||
public function processVerification(Request $request, ClientGatewaytoken $payment_method)
|
public function processVerification(Request $request, ClientGatewaytoken $payment_method)
|
||||||
{
|
{
|
||||||
$gateway = $this->getClientGateway();
|
// $gateway = $this->getClientGateway();
|
||||||
|
|
||||||
return $gateway
|
return $payment_method->gateway
|
||||||
->driver(auth()->user()->client)
|
->driver(auth()->user()->client)
|
||||||
->setPaymentMethod(request()->query('method'))
|
->setPaymentMethod(request()->query('method'))
|
||||||
->processVerification($request, $payment_method);
|
->processVerification($request, $payment_method);
|
||||||
@ -118,9 +118,9 @@ class PaymentMethodController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function destroy(ClientGatewayToken $payment_method)
|
public function destroy(ClientGatewayToken $payment_method)
|
||||||
{
|
{
|
||||||
$gateway = $this->getClientGateway();
|
// $gateway = $this->getClientGateway();
|
||||||
|
|
||||||
$gateway
|
$payment_method->gateway
|
||||||
->driver(auth()->user()->client)
|
->driver(auth()->user()->client)
|
||||||
->setPaymentMethod(request()->query('method'))
|
->setPaymentMethod(request()->query('method'))
|
||||||
->detach($payment_method);
|
->detach($payment_method);
|
||||||
|
@ -167,7 +167,7 @@ class ACH
|
|||||||
return $this->processUnsuccessfulPayment($state);
|
return $this->processUnsuccessfulPayment($state);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
if ($e instanceof CardException) {
|
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());
|
throw new PaymentFailed($e->getMessage(), $e->getCode());
|
||||||
|
@ -13,13 +13,16 @@
|
|||||||
namespace App\PaymentDrivers\WePay;
|
namespace App\PaymentDrivers\WePay;
|
||||||
|
|
||||||
use App\Exceptions\PaymentFailed;
|
use App\Exceptions\PaymentFailed;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Models\ClientGatewayToken;
|
use App\Models\ClientGatewayToken;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
use App\PaymentDrivers\WePayPaymentDriver;
|
use App\PaymentDrivers\WePayPaymentDriver;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class ACH
|
class ACH
|
||||||
{
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
public $wepay_payment_driver;
|
public $wepay_payment_driver;
|
||||||
|
|
||||||
public function __construct(WePayPaymentDriver $wepay_payment_driver)
|
public function __construct(WePayPaymentDriver $wepay_payment_driver)
|
||||||
@ -115,15 +118,30 @@ class ACH
|
|||||||
*/
|
*/
|
||||||
public function processVerification(Request $request, ClientGatewayToken $token)
|
public function processVerification(Request $request, ClientGatewayToken $token)
|
||||||
{
|
{
|
||||||
|
$transactions = $request->input('transactions');
|
||||||
|
|
||||||
|
$transformed_transactions = [];
|
||||||
|
|
||||||
|
foreach($transactions as $transaction)
|
||||||
|
$transformed_transactions[] = (int)$transaction;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
$response = $this->wepay_payment_driver->wepay->request('payment_bank/verify', [
|
$response = $this->wepay_payment_driver->wepay->request('payment_bank/verify', [
|
||||||
'client_id' => config('ninja.wepay.client_id'),
|
'client_id' => config('ninja.wepay.client_id'),
|
||||||
'client_secret' => config('ninja.wepay.client_secret'),
|
'client_secret' => config('ninja.wepay.client_secret'),
|
||||||
'payment_bank_id' => $token->token,
|
'payment_bank_id' => $token->token,
|
||||||
'type' => 'microdeposits',
|
'type' => 'microdeposits',
|
||||||
'microdeposits' => $request->input('transactions'),
|
'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,
|
"payment_bank_id": 12345,
|
||||||
@ -132,20 +150,23 @@ class ACH
|
|||||||
"state": "authorized"
|
"state": "authorized"
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
nlog($response);
|
||||||
|
|
||||||
//$meta = $token->meta;
|
//$meta = $token->meta;
|
||||||
if($response->state == "authorized")
|
if($response->state == "authorized")
|
||||||
{
|
{
|
||||||
|
$meta = $token->meta;
|
||||||
$token->routing_number = $response->state;
|
$meta->state = $response->state;
|
||||||
|
$token->meta;
|
||||||
$token->save();
|
$token->save();
|
||||||
|
|
||||||
redirect()->route('client.payment_methods.index');
|
return redirect()->route('client.payment_methods.index');
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
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());
|
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();
|
// $this->stripe->init();
|
||||||
|
|
||||||
@ -242,12 +298,12 @@ class ACH
|
|||||||
$payment_meta->brand = (string) $response->bank_name;
|
$payment_meta->brand = (string) $response->bank_name;
|
||||||
$payment_meta->last4 = (string) $response->account_last_four;
|
$payment_meta->last4 = (string) $response->account_last_four;
|
||||||
$payment_meta->type = GatewayType::BANK_TRANSFER;
|
$payment_meta->type = GatewayType::BANK_TRANSFER;
|
||||||
|
$payment_meta->state = $response->state;
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'payment_meta' => $payment_meta,
|
'payment_meta' => $payment_meta,
|
||||||
'token' => $response->payment_bank_id,
|
'token' => $response->payment_bank_id,
|
||||||
'payment_method_id' => $payment_method_id,
|
'payment_method_id' => $payment_method_id,
|
||||||
'routing_number' => $response->state,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->wepay_payment_driver->storeGatewayToken($data);
|
$this->wepay_payment_driver->storeGatewayToken($data);
|
||||||
|
@ -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)
|
private function storePaymentMethod($response, $payment_method_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -109,5 +137,7 @@ class CreditCard
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +134,20 @@ class WePayPaymentDriver extends BaseDriver
|
|||||||
return $this->payment_method->authorizeResponse($request); //this is your custom implementation from here
|
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)
|
public function processPaymentView(array $data)
|
||||||
{
|
{
|
||||||
return $this->payment_method->paymentView($data); //this is your custom implementation from here
|
return $this->payment_method->paymentView($data); //this is your custom implementation from here
|
||||||
|
@ -4256,6 +4256,7 @@ $LANG = array(
|
|||||||
'user_cross_linked_error' => 'User exists but cannot be crossed linked to multiple accounts',
|
'user_cross_linked_error' => 'User exists but cannot be crossed linked to multiple accounts',
|
||||||
'company_import_failure_subject' => 'Error importing :company',
|
'company_import_failure_subject' => 'Error importing :company',
|
||||||
'company_import_failure_body' => 'There was an error importing the company data, the error message was:',
|
'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;
|
return $LANG;
|
||||||
|
@ -10,11 +10,11 @@
|
|||||||
<input type="hidden" name="customer" value="{{ $token->gateway_customer_reference }}">
|
<input type="hidden" name="customer" value="{{ $token->gateway_customer_reference }}">
|
||||||
<input type="hidden" name="source" value="{{ $token->token }}">
|
<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">
|
<input type="text" name="transactions[]" class="w-full input" required data-cy="verification-1st">
|
||||||
@endcomponent
|
@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">
|
<input type="text" name="transactions[]" class="w-full input" required data-cy="verification-2nd">
|
||||||
@endcomponent
|
@endcomponent
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@
|
|||||||
@csrf
|
@csrf
|
||||||
<input type="hidden" name="token" value="{{ $token->token }}">
|
<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">
|
<input type="text" name="transactions[]" class="w-full input" required data-cy="verification-1st">
|
||||||
@endcomponent
|
@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">
|
<input type="text" name="transactions[]" class="w-full input" required data-cy="verification-2nd">
|
||||||
@endcomponent
|
@endcomponent
|
||||||
|
|
||||||
|
@ -43,5 +43,15 @@
|
|||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@push('footer')
|
@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
|
@endpush
|
||||||
|
Loading…
x
Reference in New Issue
Block a user