@@ -44,7 +44,7 @@ public function __construct() {
44
44
$ this ->go_live = $ this ->get_option ( 'go_live ' );
45
45
$ this ->payment_options = $ this ->get_option ( 'payment_options ' );
46
46
$ this ->payment_style = $ this ->get_option ( 'payment_style ' );
47
- // $this->country = $this->get_option( 'country ' );
47
+ $ this ->barter = $ this ->get_option ( 'barter ' );
48
48
// $this->modal_logo = $this->get_option( 'modal_logo' );
49
49
50
50
// enable saved cards
@@ -117,6 +117,14 @@ public function init_form_fields() {
117
117
'default ' => 'no ' ,
118
118
'desc_tip ' => true
119
119
),
120
+ 'barter ' => array (
121
+ 'title ' => __ ( 'Disable Barter ' , 'flw-payments ' ),
122
+ 'label ' => __ ( 'Disable Barter ' , 'flw-payments ' ),
123
+ 'type ' => 'checkbox ' ,
124
+ 'description ' => __ ( 'Check the box if you want to disable barter. ' , 'flw-payments ' ),
125
+ 'default ' => 'no ' ,
126
+ 'desc_tip ' => true
127
+ ),
120
128
'webhook ' => array (
121
129
'title ' => __ ( 'Webhook Instruction ' , 'flw-payments ' ),
122
130
'type ' => 'hidden ' ,
@@ -189,23 +197,6 @@ public function init_form_fields() {
189
197
),
190
198
'default ' => ''
191
199
),
192
- // 'country' => array(
193
- // 'title' => __( 'Charge Country', 'flw-payments' ),
194
- // 'type' => 'select',
195
- // 'description' => __( 'Optional - Charge country. (Default: NG)', 'flw-payments' ),
196
- // 'options' => array(
197
- // 'NG' => esc_html_x( 'NG', 'country', 'flw-payments' ),
198
- // 'GH' => esc_html_x( 'GH', 'country', 'flw-payments' ),
199
- // 'KE' => esc_html_x( 'KE', 'country', 'flw-payments' ),
200
- // ),
201
- // 'default' => 'NG'
202
- // ),
203
- // 'modal_logo' => array(
204
- // 'title' => __( 'Modal Custom Logo', 'flw-payments' ),
205
- // 'type' => 'text',
206
- // 'description' => __( 'Optional - URL to your store\'s logo. Preferably a square image', 'flw-payments' ),
207
- // 'default' => ''
208
- // ),
209
200
210
201
);
211
202
@@ -312,13 +303,13 @@ public function load_scripts() {
312
303
$ main_order_key = $ order ->get_order_key ();
313
304
}else {
314
305
$ args = array (
315
- 'name ' => $ order ->billing_first_name . ' ' . $ order ->billing_last_name ,
316
- 'email ' => $ order ->billing_email ,
317
- 'contact ' => $ order ->billing_phone ,
306
+ 'name ' => $ order ->get_billing_first_name () . ' ' . $ order ->get_billing_last_name () ,
307
+ 'email ' => $ order ->get_billing_email () ,
308
+ 'contact ' => $ order ->get_billing_phone () ,
318
309
);
319
- $ amount = $ order ->order_total ;
320
- $ main_order_key = $ order ->order_key ;
321
- $ email = $ order ->billing_email ;
310
+ $ amount = $ order ->get_total () ;
311
+ $ main_order_key = $ order ->get_order_key () ;
312
+ $ email = $ order ->get_billing_email () ;
322
313
$ currency = $ order ->get_order_currency ();
323
314
}
324
315
@@ -355,8 +346,9 @@ public function load_scripts() {
355
346
$ payment_args ['desc ' ] = filter_var ($ this ->description , FILTER_SANITIZE_STRING );
356
347
$ payment_args ['title ' ] = filter_var ($ this ->title , FILTER_SANITIZE_STRING );
357
348
// $payment_args['logo'] = filter_var($this->modal_logo, FILTER_SANITIZE_URL);
358
- $ payment_args ['firstname ' ] = $ order ->billing_first_name ;
359
- $ payment_args ['lastname ' ] = $ order ->billing_last_name ;
349
+ $ payment_args ['firstname ' ] = $ order ->get_billing_first_name ();
350
+ $ payment_args ['lastname ' ] = $ order ->get_billing_last_name ();
351
+ $ payment_args ['barter ' ] = $ this ->barter ;
360
352
}
361
353
362
354
update_post_meta ( $ order_id , '_flw_payment_txn_ref ' , $ txnref );
@@ -375,91 +367,90 @@ public function load_scripts() {
375
367
*/
376
368
public function flw_verify_payment () {
377
369
378
- $ publicKey = $ this ->public_key ;
379
- $ secretKey = $ this ->secret_key ;
370
+ $ publicKey = $ this ->public_key ;
371
+ $ secretKey = $ this ->secret_key ;
380
372
381
- // if($this->go_live === 'yes'){
382
- // $env = 'live';
383
- // }else{
384
- // $env = 'staging';
373
+ // if($this->go_live === 'yes'){
374
+ // $env = 'live';
375
+ // }else{
376
+ // $env = 'staging';
377
+ // }
378
+ $ overrideRef = true ;
379
+
380
+ if (isset ($ _GET ['rave_id ' ]) && urldecode ( $ _GET ['rave_id ' ] )){
381
+ $ order_id = urldecode ( $ _GET ['rave_id ' ] );
382
+
383
+ if (!$ order_id ){
384
+ $ order_id = urldecode ( $ _GET ['order_id ' ] );
385
+ }
386
+ $ order = wc_get_order ( $ order_id );
387
+
388
+ $ redirectURL = WC ()->api_request_url ( 'FLW_WC_Payment_Gateway ' ).'?order_id= ' .$ order_id ;
389
+
390
+ $ ref = uniqid ("WOOC_ " . $ order_id ."_ " .time ()."_ " );
391
+
392
+ $ payment = new Rave ($ publicKey , $ secretKey , $ ref , $ overrideRef );
393
+
394
+ // if($this->modal_logo){
395
+ // $rave_m_logo = $this->modal_logo;
385
396
// }
386
- $ overrideRef = true ;
387
-
388
- if (isset ($ _GET ['rave_id ' ]) && urldecode ( $ _GET ['rave_id ' ] )){
389
- $ order_id = urldecode ( $ _GET ['rave_id ' ] );
390
-
397
+
398
+ //set variables
399
+ $ modal_desc = $ this ->description != '' ? filter_var ($ this ->description , FILTER_SANITIZE_STRING ) : "Payment for Order ID: $ order_id on " . get_bloginfo ('name ' );
400
+ $ modal_title = $ this ->title != '' ? filter_var ($ this ->title , FILTER_SANITIZE_STRING ) : get_bloginfo ('name ' );
401
+
402
+ // Make payment
403
+ $ payment
404
+ ->eventHandler (new myEventHandler ($ order ))
405
+ ->setAmount ($ order ->get_total ())
406
+ ->setPaymentOptions ($ this ->payment_options ) // value can be card, account or both
407
+ ->setDescription ($ modal_desc )
408
+ ->setTitle ($ modal_title )
409
+ ->setCountry ($ this ->country )
410
+ ->setCurrency ($ order ->get_order_currency ())
411
+ ->setEmail ($ order ->get_billing_email ())
412
+ ->setFirstname ($ order ->get_billing_first_name ())
413
+ ->setLastname ($ order ->get_billing_last_name ())
414
+ ->setPhoneNumber ($ order ->get_billing_phone ())
415
+ ->setDisableBarter ($ this ->barter )
416
+ ->setRedirectUrl ($ redirectURL )
417
+ // ->setMetaData(array('metaname' => 'SomeDataName', 'metavalue' => 'SomeValue')) // can be called multiple times. Uncomment this to add meta datas
418
+ // ->setMetaData(array('metaname' => 'SomeOtherDataName', 'metavalue' => 'SomeOtherValue')) // can be called multiple times. Uncomment this to add meta datas
419
+ ->initialize ();
420
+ die ();
421
+ }else {
422
+ if (isset ($ _GET ['cancelled ' ]) && isset ($ _GET ['order_id ' ])){
391
423
if (!$ order_id ){
392
424
$ order_id = urldecode ( $ _GET ['order_id ' ] );
393
425
}
394
426
$ order = wc_get_order ( $ order_id );
395
-
396
- $ redirectURL = WC ()->api_request_url ( 'FLW_WC_Payment_Gateway ' ).'?order_id= ' .$ order_id ;
397
-
398
- $ ref = uniqid ("WOOC_ " . $ order_id ."_ " .time ()."_ " );
399
-
400
- $ payment = new Rave ($ publicKey , $ secretKey , $ ref , $ overrideRef );
401
-
402
- // if($this->modal_logo){
403
- // $rave_m_logo = $this->modal_logo;
404
- // }
405
-
406
- //set variables
407
- $ modal_desc = $ this ->description != '' ? filter_var ($ this ->description , FILTER_SANITIZE_STRING ) : "Payment for Order ID: $ order_id on " . get_bloginfo ('name ' );
408
- $ modal_title = $ this ->title != '' ? filter_var ($ this ->title , FILTER_SANITIZE_STRING ) : get_bloginfo ('name ' );
409
-
410
- // Make payment
411
- $ payment
412
- ->eventHandler (new myEventHandler ($ order ))
413
- ->setAmount ($ order ->order_total )
414
- ->setPaymentOptions ($ this ->payment_options ) // value can be card, account or both
415
- ->setDescription ($ modal_desc )
416
- // ->setLogo($rave_m_logo)
417
- ->setTitle ($ modal_title )
418
- ->setCountry ($ this ->country )
419
- ->setCurrency ($ order ->get_order_currency ())
420
- ->setEmail ($ order ->billing_email )
421
- ->setFirstname ($ order ->billing_first_name )
422
- ->setLastname ($ order ->billing_last_name )
423
- ->setPhoneNumber ($ order ->billing_phone )
424
- // ->setPayButtonText($postData['pay_button_text'])
425
- ->setRedirectUrl ($ redirectURL )
426
- // ->setMetaData(array('metaname' => 'SomeDataName', 'metavalue' => 'SomeValue')) // can be called multiple times. Uncomment this to add meta datas
427
- // ->setMetaData(array('metaname' => 'SomeOtherDataName', 'metavalue' => 'SomeOtherValue')) // can be called multiple times. Uncomment this to add meta datas
428
- ->initialize ();
429
- die ();
430
- }else {
431
- if (isset ($ _GET ['cancelled ' ]) && isset ($ _GET ['order_id ' ])){
432
- if (!$ order_id ){
433
- $ order_id = urldecode ( $ _GET ['order_id ' ] );
434
- }
427
+ $ redirectURL = $ order ->get_checkout_payment_url ( true );
428
+ header ("Location: " .$ redirectURL );
429
+ die ();
430
+ }
431
+
432
+ if ( isset ( $ _POST ['txRef ' ] ) || isset ($ _GET ['txref ' ]) ) {
433
+ $ txn_ref = isset ($ _POST ['txRef ' ]) ? $ _POST ['txRef ' ] : urldecode ($ _GET ['txref ' ]);
434
+ $ o = explode ('_ ' , $ txn_ref );
435
+ $ order_id = intval ( $ o [1 ] );
435
436
$ order = wc_get_order ( $ order_id );
436
- $ redirectURL = $ order ->get_checkout_payment_url ( true );
437
- header ("Location: " .$ redirectURL );
437
+ $ payment = new Rave ($ publicKey , $ secretKey , $ txn_ref , $ overrideRef );
438
+
439
+ $ payment ->logger ->notice ('Payment completed. Now requerying payment. ' );
440
+
441
+ $ payment ->eventHandler (new myEventHandler ($ order ))->requeryTransaction (urldecode ($ txn_ref ));
442
+
443
+ $ redirect_url = $ this ->get_return_url ( $ order );
444
+ header ("Location: " .$ redirect_url );
438
445
die ();
439
- }
440
-
441
- if ( isset ( $ _POST ['txRef ' ] ) || isset ($ _GET ['txref ' ]) ) {
442
- $ txn_ref = isset ($ _POST ['txRef ' ]) ? $ _POST ['txRef ' ] : urldecode ($ _GET ['txref ' ]);
443
- $ o = explode ('_ ' , $ txn_ref );
444
- $ order_id = intval ( $ o [1 ] );
445
- $ order = wc_get_order ( $ order_id );
446
- $ payment = new Rave ($ publicKey , $ secretKey , $ txn_ref , $ env , $ overrideRef );
447
-
448
- $ payment ->logger ->notice ('Payment completed. Now requerying payment. ' );
449
-
450
- $ payment ->eventHandler (new myEventHandler ($ order ))->requeryTransaction (urldecode ($ txn_ref ));
451
-
452
- $ redirect_url = $ this ->get_return_url ( $ order );
453
- header ("Location: " .$ redirect_url );
454
- die ();
455
- }else {
456
- $ payment = new Rave ($ publicKey , $ secretKey , $ txn_ref , $ env , $ overrideRef );
446
+ }else {
447
+ $ payment = new Rave ($ publicKey , $ secretKey , $ txn_ref , $ overrideRef );
448
+
449
+ $ payment ->logger ->notice ('Error with requerying payment. ' );
457
450
458
- $ payment ->logger ->notice ('Error with requerying payment. ' );
459
-
460
- $ payment ->eventHandler (new myEventHandler ($ order ))->doNothing ();
461
- die ();
462
- }
451
+ $ payment ->eventHandler (new myEventHandler ($ order ))->doNothing ();
452
+ die ();
453
+ }
463
454
}
464
455
}
465
456
@@ -546,31 +537,7 @@ public static function save_card_details( $rave_response, $user_id, $order_id )
546
537
self ::save_subscription_payment_token ( $ order_id , $ token_code );
547
538
// $save_card = get_post_meta( $order_id, '_wc_rave_save_card', true );
548
539
549
- // if ( isset( $rave_response->data->card ) && $user_id && self::saved_cards && $save_card && ! empty( $token_code ) ) {
550
-
551
- // $last4 = $rave_response->data->card->last4digits;
552
-
553
- // if ( 4 !== strlen( $rave_response->data->card->expiryyear ) ) {
554
- // $exp_year = substr( date( 'Y' ), 0, 2 ) . $rave_response->data->card->expiryyear;
555
- // } else {
556
- // $exp_year = $rave_response->data->card->expiryyear;
557
- // }
558
-
559
- // $brand = $rave_response->data->card->brand;
560
- // $exp_month = $rave_response->data->card->expirymonth;
561
- // $token = new WC_Payment_Token_CC();
562
- // $token->set_token( $token_code );
563
- // $token->set_gateway_id( 'rave' );
564
- // $token->set_card_type( $brand );
565
- // $token->set_last4( $last4 );
566
- // $token->set_expiry_month( $exp_month );
567
- // $token->set_expiry_year( $exp_year );
568
- // $token->set_user_id( $user_id );
569
- // $token->save();
570
-
571
- // }
572
-
573
- // delete_post_meta( $order_id, '_wc_rave_save_card' );
540
+
574
541
}
575
542
576
543
/**
0 commit comments