diff --git a/app/PaymentDrivers/WePay/CreditCard.php b/app/PaymentDrivers/WePay/CreditCard.php
index bd2ae07b6..5d8bc96d4 100644
--- a/app/PaymentDrivers/WePay/CreditCard.php
+++ b/app/PaymentDrivers/WePay/CreditCard.php
@@ -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);
}
}
diff --git a/app/PaymentDrivers/WePayPaymentDriver.php b/app/PaymentDrivers/WePayPaymentDriver.php
index 172607bc4..7245528a9 100644
--- a/app/PaymentDrivers/WePayPaymentDriver.php
+++ b/app/PaymentDrivers/WePayPaymentDriver.php
@@ -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
}
diff --git a/resources/views/portal/ninja2020/gateways/wepay/authorize/authorize.blade.php b/resources/views/portal/ninja2020/gateways/wepay/authorize/authorize.blade.php
index bc6a688ed..160fdd847 100644
--- a/resources/views/portal/ninja2020/gateways/wepay/authorize/authorize.blade.php
+++ b/resources/views/portal/ninja2020/gateways/wepay/authorize/authorize.blade.php
@@ -7,7 +7,6 @@
-
@endsection
@@ -20,6 +19,7 @@
+
@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($('').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();
+
}
});
});