mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Authorize credit card
This commit is contained in:
parent
177a4ce58f
commit
8fd4a3f202
@ -16,20 +16,19 @@ use App\PaymentDrivers\WePayPaymentDriver;
|
||||
|
||||
class CreditCard
|
||||
{
|
||||
public $wepay;
|
||||
public $wepay_payment_driver;
|
||||
|
||||
public function __construct(WePayPaymentDriver $wepay)
|
||||
public function __construct(WePayPaymentDriver $wepay_payment_driver)
|
||||
{
|
||||
$this->wepay = $wepay;
|
||||
$this->wepay_payment_driver = $wepay_payment_driver;
|
||||
}
|
||||
|
||||
public function authorizeView($data)
|
||||
{
|
||||
$data['gateway'] = $this->wepay;
|
||||
$data['gateway'] = $this->wepay_payment_driver;
|
||||
|
||||
return render('gateways.wepay.authorize.authorize', $data);
|
||||
}
|
||||
|
||||
|
||||
public function authorizeResponse($request)
|
||||
{
|
||||
@ -37,14 +36,18 @@ class CreditCard
|
||||
|
||||
$data = $request->all();
|
||||
// authorize the credit card
|
||||
$response = $this->wepay->request('credit_card/authorize', array(
|
||||
'account_id' => $this->wepay->company_gateway->getConfigField('accountId'),
|
||||
|
||||
nlog($data);
|
||||
|
||||
$response = $this->wepay_payment_driver->wepay->request('credit_card/authorize', array(
|
||||
'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'),
|
||||
'client_id' => config('ninja.wepay.client_id'),
|
||||
'client_secret' => config('ninja.wepay.client_secret'),
|
||||
'credit_card_id' => $data['source_token'],
|
||||
'credit_card_id' => $data['credit_card_id'],
|
||||
));
|
||||
|
||||
// display the response
|
||||
print_r($response);
|
||||
nlog($response);
|
||||
}
|
||||
}
|
||||
|
@ -114,6 +114,8 @@ class WePayPaymentDriver extends BaseDriver
|
||||
|
||||
public function authorizeView(array $data)
|
||||
{
|
||||
$this->init();
|
||||
|
||||
$data['gateway'] = $this->wepay;
|
||||
$client = $data['client'];
|
||||
$contact = $client->primary_contact()->first() ? $client->primary_contact()->first() : $lient->contacts->first();
|
||||
@ -127,6 +129,8 @@ class WePayPaymentDriver extends BaseDriver
|
||||
|
||||
public function authorizeResponse($request)
|
||||
{
|
||||
$this->init();
|
||||
|
||||
return $this->payment_method->authorizeResponse($request); //this is your custom implementation from here
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
|
||||
<script src="{{ asset('js/clients/payments/card-js.min.js') }}"></script>
|
||||
|
||||
<link href="{{ asset('css/card-js.min.css') }}" rel="stylesheet" type="text/css">
|
||||
@endsection
|
||||
|
||||
@ -20,6 +19,7 @@
|
||||
<input type="hidden" name="payment_method_id" value="1">
|
||||
<input type="hidden" name="gateway_response" id="gateway_response">
|
||||
<input type="hidden" name="is_default" id="is_default">
|
||||
<input type="hidden" name="credit_card_id" id="credit_card_id">
|
||||
</form>
|
||||
|
||||
@if(!Request::isSecure())
|
||||
@ -66,6 +66,7 @@
|
||||
addEvent(document.getElementById('card_button'), 'click', function() {
|
||||
|
||||
var myCard = $('#my-card');
|
||||
|
||||
var userName = [valueById('cardholder_name')].join(' ');
|
||||
response = WePay.credit_card.create({
|
||||
"client_id": "{{ config('ninja.wepay.client_id') }}",
|
||||
@ -81,15 +82,22 @@
|
||||
}, function(data) {
|
||||
if (data.error) {
|
||||
console.log(data);
|
||||
// handle error response
|
||||
// handle error response error_description
|
||||
let errors = document.getElementById('errors');
|
||||
errors.textContent = '';
|
||||
errors.textContent = data.error_description;
|
||||
errors.hidden = false;
|
||||
} else {
|
||||
// call your own app's API to save the token inside the data;
|
||||
// show a success page
|
||||
var token = response.credit_card_id;
|
||||
var token = data.credit_card_id;
|
||||
// Insert the token into the form so it gets submitted to the server
|
||||
$form.append($('<input type="hidden" name="source_token"/>').val(token));
|
||||
// and submit
|
||||
$form.get(0).submit();
|
||||
// console.log(data);
|
||||
|
||||
document.querySelector('input[name="credit_card_id"]').value = token;
|
||||
|
||||
document.getElementById('server_response').submit();
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user