Skip to content

Commit 391ef80

Browse files
committed
Version 4.1.0
1 parent ff69410 commit 391ef80

5 files changed

Lines changed: 254 additions & 61 deletions

File tree

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
**Requires at least:** 4.4
1010

11-
**Tested up to:** 4.7
11+
**Tested up to:** 4.8
1212

13-
**Stable tag:** 4.0.1
13+
**Stable tag:** 4.1.0
1414

1515
**License:** GPLv2 or later
1616

@@ -23,15 +23,15 @@ Paystack WooCommerce Payment Gateway allows you to accept online payments from l
2323

2424
## Description
2525

26-
This is a Paystack payment gateway for Woocommerce.
26+
This is a Paystack payment gateway for WooCommerce.
2727

2828
Paystack is on a mission to deliver a safe and convenient payment experience for customers and merchants. Paystack provide Nigerian merchants with the tools and services needed to accept online payments from local and international customers using MasterCard, Visa and Verve Cards.
2929

3030
To signup for a Paystack Merchant account visit their website by clicking [here](https://paystack.com)
3131

32-
Paystack Woocommerce Payment Gateway allows you to accept payment on your Woocommerce store using MasterCard, Visa and Verve Cards.
32+
Paystack WooCommerce Payment Gateway allows you to accept payment on your Woocommerce store using MasterCard, Visa and Verve Cards.
3333

34-
With this Paystack Woocommerce Payment Gateway plugin, you will be able to accept the following payment methods in your shop:
34+
With this Paystack WooCommerce Payment Gateway plugin, you will be able to accept the following payment methods in your shop:
3535

3636
* __MasterCard__
3737
* __Visa__
@@ -141,6 +141,9 @@ To configure the plugin, go to __WooCommerce > Settings__ from the left hand me
141141

142142
## Changelog
143143

144+
### 4.1.0, July 7, 2017 ###
145+
* Fix: Deprecated WooCommerce 2.X functions
146+
144147
### 4.0.1, April 10, 2017 ###
145148
* Fix: Fatal error if WooCommerce 2.6.14 and below is installed
146149

@@ -183,8 +186,8 @@ To configure the plugin, go to __WooCommerce > Settings__ from the left hand me
183186

184187
## Upgrade Notice
185188

186-
### 4.0.1
187-
* Fix fatal error if WooCommerce 2.6.14 and below is installed
189+
### 4.1.0
190+
* Fix: Deprecated WooCommerce 2.X functions
188191

189192

190193

includes/class-paystack-deprecated.php

Lines changed: 205 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,20 @@ public function __construct() {
3838
$this->public_key = $this->testmode ? $this->test_public_key : $this->live_public_key;
3939
$this->secret_key = $this->testmode ? $this->test_secret_key : $this->live_secret_key;
4040

41+
$this->custom_metadata = $this->get_option( 'custom_metadata' ) === 'yes' ? true : false;
42+
43+
$this->meta_order_id = $this->get_option( 'meta_order_id' ) === 'yes' ? true : false;
44+
$this->meta_name = $this->get_option( 'meta_name' ) === 'yes' ? true : false;
45+
$this->meta_email = $this->get_option( 'meta_email' ) === 'yes' ? true : false;
46+
$this->meta_phone = $this->get_option( 'meta_phone' ) === 'yes' ? true : false;
47+
$this->meta_billing_address = $this->get_option( 'meta_billing_address' ) === 'yes' ? true : false;
48+
$this->meta_shipping_address= $this->get_option( 'meta_shipping_address' ) === 'yes' ? true : false;
49+
$this->meta_products = $this->get_option( 'meta_products' ) === 'yes' ? true : false;
50+
4151
// Hooks
4252
add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
53+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
54+
4355
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
4456
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
4557

@@ -135,7 +147,7 @@ public function admin_options() {
135147

136148
<h3>Paystack</h3>
137149

138-
<h4>Optional: To avoid situations where bad network makes it impossible to verify transactions, set your webhook URL <a href="https://dashboard.paystack.co/#/settings/developer">here</a> to the URL below<strong style="color: red"><pre><code><?php echo WC()->api_request_url( 'Tbz_WC_Paystack_Webhook' ); ?></code></pre></strong></h4>
150+
<h4>Optional: To avoid situations where bad network makes it impossible to verify transactions, set your webhook URL <a href="https://dashboard.paystack.co/#/settings/developer" target="_blank" rel="noopener noreferrer">here</a> to the URL below<strong style="color: red"><pre><code><?php echo WC()->api_request_url( 'Tbz_WC_Paystack_Webhook' ); ?></code></pre></strong></h4>
139151

140152
<?php
141153

@@ -164,7 +176,7 @@ public function init_form_fields() {
164176
'title' => 'Enable/Disable',
165177
'label' => 'Enable Paystack',
166178
'type' => 'checkbox',
167-
'description' => 'Enable Paystack as a payment option on the checkout page',
179+
'description' => 'Enable Paystack as a payment option on the checkout page.',
168180
'default' => 'no',
169181
'desc_tip' => true
170182
),
@@ -182,6 +194,14 @@ public function init_form_fields() {
182194
'desc_tip' => true,
183195
'default' => 'Make payment using your debit and credit cards'
184196
),
197+
'testmode' => array(
198+
'title' => 'Test mode',
199+
'label' => 'Enable Test Mode',
200+
'type' => 'checkbox',
201+
'description' => 'Test mode enables you to test payments before going live. <br />Once the LIVE MODE is enabled on your Paystack account uncheck this.',
202+
'default' => 'yes',
203+
'desc_tip' => true
204+
),
185205
'payment_page' => array(
186206
'title' => 'Payment Page',
187207
'type' => 'select',
@@ -194,14 +214,6 @@ public function init_form_fields() {
194214
'embed' => 'Inline Embed'
195215
)
196216
),
197-
'testmode' => array(
198-
'title' => 'Test mode',
199-
'label' => 'Enable Test Mode',
200-
'type' => 'checkbox',
201-
'description' => 'Test mode enables you to test payments before going live. <br />Once the LIVE MODE is enabled on your Paystack account uncheck this.',
202-
'default' => 'yes',
203-
'desc_tip' => true
204-
),
205217
'test_secret_key' => array(
206218
'title' => 'Test Secret Key',
207219
'type' => 'text',
@@ -226,6 +238,70 @@ public function init_form_fields() {
226238
'description' => 'Enter your Live Public Key here.',
227239
'default' => ''
228240
),
241+
'custom_metadata' => array(
242+
'title' => 'Custom Metadata',
243+
'label' => 'Enable Custom Metadata',
244+
'type' => 'checkbox',
245+
'description' => 'If enabled, you will be able to send more information about the order to Paystack.',
246+
'default' => 'no',
247+
'desc_tip' => true
248+
),
249+
'meta_order_id' => array(
250+
'title' => 'Order ID',
251+
'label' => 'Send Order ID',
252+
'type' => 'checkbox',
253+
'description' => 'If checked, the Order ID will be sent to Paystack',
254+
'default' => 'no',
255+
'desc_tip' => true
256+
),
257+
'meta_name' => array(
258+
'title' => 'Customer Name',
259+
'label' => 'Send Customer Name',
260+
'type' => 'checkbox',
261+
'description' => 'If checked, the customer full name will be sent to Paystack',
262+
'default' => 'no',
263+
'desc_tip' => true
264+
),
265+
'meta_email' => array(
266+
'title' => 'Customer Email',
267+
'label' => 'Send Customer Email',
268+
'type' => 'checkbox',
269+
'description' => 'If checked, the customer email address will be sent to Paystack',
270+
'default' => 'no',
271+
'desc_tip' => true
272+
),
273+
'meta_phone' => array(
274+
'title' => 'Customer Phone',
275+
'label' => 'Send Customer Phone',
276+
'type' => 'checkbox',
277+
'description' => 'If checked, the customer phone will be sent to Paystack',
278+
'default' => 'no',
279+
'desc_tip' => true
280+
),
281+
'meta_billing_address' => array(
282+
'title' => 'Order Billing Address',
283+
'label' => 'Send Order Billing Address',
284+
'type' => 'checkbox',
285+
'description' => 'If checked, the order billing address will be sent to Paystack',
286+
'default' => 'no',
287+
'desc_tip' => true
288+
),
289+
'meta_shipping_address' => array(
290+
'title' => 'Order Shipping Address',
291+
'label' => 'Send Order Shipping Address',
292+
'type' => 'checkbox',
293+
'description' => 'If checked, the order shipping address will be sent to Paystack',
294+
'default' => 'no',
295+
'desc_tip' => true
296+
),
297+
'meta_products' => array(
298+
'title' => 'Product(s) Purchased',
299+
'label' => 'Send Product(s) Purchased',
300+
'type' => 'checkbox',
301+
'description' => 'If checked, the product(s) purchased will be sent to Paystack',
302+
'default' => 'no',
303+
'desc_tip' => true
304+
),
229305
);
230306

231307
}
@@ -236,41 +312,125 @@ public function init_form_fields() {
236312
*/
237313
public function payment_scripts() {
238314

239-
if ( $this->description ) {
240-
echo wpautop( wptexturize( $this->description ) );
241-
}
242-
243315
if ( ! is_checkout_pay_page() ) {
244316
return;
245317
}
246318

247319
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
248320

249-
wp_enqueue_script( 'paystack', 'https://js.paystack.co/v1/inline.js', array( 'jquery' ), WC_PAYSTACK_VERSION, true );
321+
wp_enqueue_script( 'jquery' );
322+
323+
wp_enqueue_script( 'paystack', 'https://js.paystack.co/v1/inline.js', array( 'jquery' ), WC_PAYSTACK_VERSION, false );
250324

251-
wp_enqueue_script( 'wc_paystack', plugins_url( 'assets/js/paystack'. $suffix . '.js', WC_PAYSTACK_MAIN_FILE ), array('paystack'), WC_PAYSTACK_VERSION, true );
325+
wp_enqueue_script( 'wc_paystack', plugins_url( 'assets/js/paystack'. $suffix . '.js', WC_PAYSTACK_MAIN_FILE ), array( 'jquery', 'paystack' ), WC_PAYSTACK_VERSION, false );
252326

253327
$paystack_params = array(
254328
'key' => $this->public_key
255329
);
256330

257331
if ( is_checkout_pay_page() && get_query_var( 'order-pay' ) ) {
258332

259-
$order_key = urldecode( $_GET['key'] );
260-
$order_id = absint( get_query_var( 'order-pay' ) );
333+
$order_key = urldecode( $_GET['key'] );
334+
$order_id = absint( get_query_var( 'order-pay' ) );
261335

262-
$order = wc_get_order( $order_id );
263-
$email = $order->billing_email;
264-
$amount = $order->order_total * 100;
336+
$order = wc_get_order( $order_id );
337+
338+
$email = method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email;
339+
340+
$amount = $order->get_total() * 100;
265341

266342
$txnref = $order_id . '_' .time();
267343

268-
if ( $order->id == $order_id && $order->order_key == $order_key ) {
344+
$the_order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
345+
$the_order_key = method_exists( $order, 'get_order_key' ) ? $order->get_order_key() : $order->order_key;
346+
347+
if ( $the_order_id == $order_id && $the_order_key == $order_key ) {
348+
349+
$paystack_params['email'] = $email;
350+
$paystack_params['amount'] = $amount;
351+
$paystack_params['txnref'] = $txnref;
352+
$paystack_params['pay_page'] = $this->payment_page;
353+
$paystack_params['currency'] = get_woocommerce_currency();
354+
355+
}
356+
357+
if( $this->custom_metadata ) {
358+
359+
if( $this->meta_order_id ) {
360+
361+
$paystack_params['meta_order_id'] = $order_id;
362+
363+
}
364+
365+
if( $this->meta_name ) {
366+
367+
$first_name = method_exists( $order, 'get_billing_first_name' ) ? $order->get_billing_first_name() : $order->billing_first_name;
368+
$last_name = method_exists( $order, 'get_billing_last_name' ) ? $order->get_billing_last_name() : $order->billing_last_name;
369+
370+
$paystack_params['meta_name'] = $first_name . ' ' . $last_name;
371+
372+
}
373+
374+
if( $this->meta_email ) {
375+
376+
$paystack_params['meta_email'] = $email;
377+
378+
}
379+
380+
if( $this->meta_phone ) {
381+
382+
$billing_phone = method_exists( $order, 'get_billing_phone' ) ? $order->get_billing_phone() : $order->billing_phone;
383+
384+
$paystack_params['meta_phone'] = $billing_phone;
385+
386+
}
387+
388+
if( $this->meta_products ) {
389+
390+
$line_items = $order->get_items();
391+
392+
$products = '';
393+
394+
foreach ( $line_items as $item_id => $item ) {
395+
$name = $item['name'];
396+
$quantity = $item['qty'];
397+
$products .= $name .' (Qty: ' . $quantity .')';
398+
$products .= ' | ';
399+
}
400+
401+
$products = rtrim( $products, ' | ' );
402+
403+
$paystack_params['meta_products'] = $products;
404+
405+
}
406+
407+
if( $this->meta_billing_address ) {
408+
409+
$billing_address = $order->get_formatted_billing_address();
410+
$billing_address = esc_html( preg_replace( '#<br\s*/?>#i', ', ', $billing_address ) );
411+
412+
$paystack_params['meta_billing_address'] = $billing_address;
413+
414+
}
415+
416+
if( $this->meta_shipping_address ) {
417+
418+
$shipping_address = $order->get_formatted_shipping_address();
419+
$shipping_address = esc_html( preg_replace( '#<br\s*/?>#i', ', ', $shipping_address ) );
420+
421+
if( empty( $shipping_address ) ) {
422+
423+
$billing_address = $order->get_formatted_billing_address();
424+
$billing_address = esc_html( preg_replace( '#<br\s*/?>#i', ', ', $billing_address ) );
425+
426+
$shipping_address = $billing_address;
427+
428+
}
429+
430+
$paystack_params['meta_shipping_address'] = $shipping_address;
431+
432+
}
269433

270-
$paystack_params['email'] = $email;
271-
$paystack_params['amount'] = $amount;
272-
$paystack_params['txnref'] = $txnref;
273-
$paystack_params['currency'] = get_woocommerce_currency();
274434

275435
}
276436

@@ -283,6 +443,22 @@ public function payment_scripts() {
283443
}
284444

285445

446+
/**
447+
* Load admin scripts
448+
*/
449+
public function admin_scripts() {
450+
451+
if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) {
452+
return;
453+
}
454+
455+
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
456+
457+
wp_enqueue_script( 'wc_paystack_admin', plugins_url( 'assets/js/paystack-admin' . $suffix . '.js', WC_PAYSTACK_MAIN_FILE ), array(), WC_PAYSTACK_VERSION, true );
458+
459+
}
460+
461+
286462
/**
287463
* Process the payment
288464
*/
@@ -368,7 +544,7 @@ public function verify_paystack_transaction() {
368544

369545
$order_total = $order->get_total();
370546

371-
$order_currency = $order->get_order_currency();
547+
$order_currency = method_exists( $order, 'get_currency' ) ? $order->get_currency() : $order->get_order_currency();
372548

373549
$currency_symbol = get_woocommerce_currency_symbol( $order_currency );
374550

@@ -458,7 +634,7 @@ public function process_webhooks() {
458634

459635
$order_id = (int) $order_details[0];
460636

461-
$order = wc_get_order($order_id);
637+
$order = wc_get_order( $order_id );
462638

463639
$paystack_txn_ref = get_post_meta( $order_id, '_paystack_txn_ref', true );
464640

@@ -470,7 +646,7 @@ public function process_webhooks() {
470646
exit;
471647
}
472648

473-
$order_currency = $order->get_order_currency();
649+
$order_currency = method_exists( $order, 'get_currency' ) ? $order->get_currency() : $order->get_order_currency();
474650

475651
$currency_symbol = get_woocommerce_currency_symbol( $order_currency );
476652

0 commit comments

Comments
 (0)