Skip to content

Commit db639f4

Browse files
Merge pull request #11 from emmajiugo/master
Race Woocommerce v2.2.1
2 parents b8804ea + 5a916e6 commit db639f4

File tree

5 files changed

+133
-132
lines changed

5 files changed

+133
-132
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
- **Contributors:** Flutterwave Developers
44
- **Tags:** rave, woocommerce, payment gateway, bank account, credit card, debit card, nigeria, kenya, international, mastercard, visa, barter
55
- **Requires at least:** 4.4
6-
- **Tested up to:** 5.1.1
7-
- **Stable tag:** 2.2.0
6+
- **Tested up to:** 5.2.1
7+
- **Stable tag:** 2.2.1
88
- **License:** MIT - see below
99

1010
Take payments on your store using Rave.

assets/js/flw.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var amount = flw_payment_args.amount,
3030
txref = flw_payment_args.txnref,
3131
paymentOptions = flw_payment_args.payment_options,
3232
paymentStyle = flw_payment_args.payment_style,
33+
disableBarter = flw_payment_args.barter,
3334
redirect_url;
3435

3536
if ( form ) {
@@ -68,7 +69,8 @@ switch (curr) {
6869
var processPayment = function() {
6970
// console.log(firstname+" .......... "+lastname);
7071

71-
var popup = getpaidSetup({
72+
// setup payload
73+
var ravePayload = {
7274
amount: amount,
7375
country: country,
7476
currency: curr,
@@ -93,7 +95,15 @@ var processPayment = function() {
9395

9496
popup.close(); // close modal
9597
}
96-
});
98+
}
99+
100+
// disable barter or not
101+
if(disableBarter == 'yes'){
102+
ravePayload.disable_pwb = true;
103+
}
104+
105+
// add payload
106+
var popup = getpaidSetup(ravePayload);
97107

98108
};
99109

flutterwave-rave-php-sdk/lib/rave.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Rave {
4747
protected $transactionData;
4848
protected $overrideTransactionReference;
4949
protected $requeryCount = 0;
50+
protected $disableBarter;
5051

5152
/**
5253
* Construct
@@ -111,6 +112,11 @@ function createCheckSum(){
111112
"redirect_url" => $this->redirectUrl,
112113
"hosted_payment" => 1
113114
);
115+
116+
// check if the user disabled barter
117+
if ($this->getDisableBarter() == 'yes'){
118+
$options['disable_pwb'] = true;
119+
}
114120

115121
ksort($options);
116122

@@ -151,6 +157,24 @@ function createReferenceNumber(){
151157
function getReferenceNumber(){
152158
return $this->txref;
153159
}
160+
161+
/**
162+
* Disable barter from the form
163+
* @param string yes/no
164+
* @return object
165+
*/
166+
function setDisableBarter($barter){
167+
$this->disableBarter = $barter;
168+
return $this;
169+
}
170+
171+
/**
172+
* gets the disable barter decision
173+
* @return string
174+
*/
175+
function getDisableBarter(){
176+
return $this->disableBarter;
177+
}
154178

155179
/**
156180
* Sets the transaction amount

includes/class.flw_wc_payment_gateway.php

Lines changed: 94 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct() {
4444
$this->go_live = $this->get_option( 'go_live' );
4545
$this->payment_options = $this->get_option( 'payment_options' );
4646
$this->payment_style = $this->get_option( 'payment_style' );
47-
// $this->country = $this->get_option( 'country' );
47+
$this->barter = $this->get_option( 'barter' );
4848
// $this->modal_logo = $this->get_option( 'modal_logo' );
4949

5050
// enable saved cards
@@ -117,6 +117,14 @@ public function init_form_fields() {
117117
'default' => 'no',
118118
'desc_tip' => true
119119
),
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+
),
120128
'webhook' => array(
121129
'title' => __( 'Webhook Instruction', 'flw-payments' ),
122130
'type' => 'hidden',
@@ -189,23 +197,6 @@ public function init_form_fields() {
189197
),
190198
'default' => ''
191199
),
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-
// ),
209200

210201
);
211202

@@ -312,13 +303,13 @@ public function load_scripts() {
312303
$main_order_key = $order->get_order_key();
313304
}else{
314305
$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(),
318309
);
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();
322313
$currency = $order->get_order_currency();
323314
}
324315

@@ -355,8 +346,9 @@ public function load_scripts() {
355346
$payment_args['desc'] = filter_var($this->description, FILTER_SANITIZE_STRING);
356347
$payment_args['title'] = filter_var($this->title, FILTER_SANITIZE_STRING);
357348
// $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;
360352
}
361353

362354
update_post_meta( $order_id, '_flw_payment_txn_ref', $txnref );
@@ -375,91 +367,90 @@ public function load_scripts() {
375367
*/
376368
public function flw_verify_payment() {
377369

378-
$publicKey = $this->public_key;
379-
$secretKey = $this->secret_key;
370+
$publicKey = $this->public_key;
371+
$secretKey = $this->secret_key;
380372

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;
385396
// }
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'])){
391423
if(!$order_id){
392424
$order_id = urldecode( $_GET['order_id'] );
393425
}
394426
$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] );
435436
$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);
438445
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.');
457450

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+
}
463454
}
464455
}
465456

@@ -546,31 +537,7 @@ public static function save_card_details( $rave_response, $user_id, $order_id )
546537
self::save_subscription_payment_token( $order_id, $token_code );
547538
// $save_card = get_post_meta( $order_id, '_wc_rave_save_card', true );
548539

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+
574541
}
575542

576543
/**

woocommerce-rave.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: Rave WooCommerce Payment Gateway
55
Plugin URI: https://rave.flutterwave.com/
66
Description: Official WooCommerce payment gateway for Rave.
7-
Version: 2.2.0
7+
Version: 2.2.1
88
Author: Flutterwave Developers
99
Author URI: http://developer.flutterwave.com
1010
License: MIT License

0 commit comments

Comments
 (0)