Skip to content

Commit

Permalink
Rebrand to Rave and implement multiple forms on a page
Browse files Browse the repository at this point in the history
  • Loading branch information
bosunolanrewaju committed Jan 3, 2017
1 parent 30f9a29 commit 69e444e
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 252 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
T License
MIT License

Copyright (c) 2016 Olatunbosun Olanrewaju

Expand Down
Binary file added assets/images/rave-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/rave-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions assets/js/flw-tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(function() {
tinymce.create('tinymce.plugins.flw_plugin', {
init: function( editor, url ) {

var assetsUrl = url.replace( '/js', '/' );
editor.addCommand('flw_insert_shortcode', function() {

var selected = tinymce.activeEditor.selection.getContent();
Expand All @@ -13,9 +13,9 @@
});

editor.addButton( 'flw_button', {
title : 'Insert shortcode',
title : 'Insert Rave payment shortcode',
cmd : 'flw_insert_shortcode',
image : 'http://sample.net/haute/wp-content/plugins/flutterwave-pay/assets/images/flutterwave-icon.png',
image : assetsUrl +'images/rave-icon.png',
} );
},
});
Expand Down
76 changes: 28 additions & 48 deletions assets/js/flw.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
'use strict';

var amount = flw_payment_args.amount,
button = flw_payment_args.button,
cbUrl = flw_payment_args.cb_url,
country = flw_payment_args.country,
currency = flw_payment_args.currency,
desc = flw_payment_args.desc,
email = flw_payment_args.email,
logo = flw_payment_args.logo,
prefix = Math.random().toString(36).substr(2, 3).toUpperCase(),
pbkey = flw_payment_args.pbkey,
form = jQuery( '.flw-simple-pay-now-form' ),
title = flw_payment_args.title,
txref, redirectUrl;
var form = jQuery( '.flw-simple-pay-now-form' ),
redirectUrl;

if ( form ) {

form.on( 'submit', function(evt) {
evt.preventDefault();
var thisForm = evt.target;
amount = amount || thisForm.querySelector( '#flw-amount' ).value;
email = email || thisForm.querySelector( '#flw-customer-email' ).value;
txref = 'WP_' + prefix + '_' + new Date().valueOf();
var config = buildConfigObj();

var config = buildConfigObj( this );
processCheckout( config );

} );
Expand All @@ -35,24 +19,27 @@ if ( form ) {
*
* @return object - The config object
*/
var buildConfigObj = function() {
var buildConfigObj = function( form ) {
var formData = jQuery( form ).data();
var amount = formData.amount || jQuery( form ).find( '#flw-amount' ).val();
var email = formData.email || jQuery( form ).find( '#flw-customer-email' ).val();
var txref = 'WP_' + form.id.toUpperCase() + '_' + new Date().valueOf();

return {
amount: amount,
country: country,
currency: currency,
custom_description: desc,
custom_logo: logo,
custom_title: title,
country: flw_rave_options.country,
currency: flw_rave_options.currency,
custom_description: flw_rave_options.desc,
custom_logo: flw_rave_options.logo,
custom_title: flw_rave_options.title,
customer_email: email,
pay_button_text: button,
PBFPubKey: pbkey,
PBFPubKey: flw_rave_options.pbkey,
txref: txref,
onclose: function() {
redirectTo( redirectUrl );
},
callback: function(d) {
sendPaymentRequestResponse( d );
callback: function(res) {
sendPaymentRequestResponse( res, form );
}
};

Expand All @@ -69,24 +56,30 @@ var processCheckout = function(opts) {
*
* @return void
*/
var sendPaymentRequestResponse = function( res ) {
var args = {
var sendPaymentRequestResponse = function( res, form ) {
var args = {
action: 'process_payment',
flw_sec_code: jQuery( '#flw_sec_code' ).val(),
flw_sec_code: jQuery( form ).find( '#flw_sec_code' ).val(),
};

var dataObj = Object.assign( {}, args, res.tx );

jQuery
.post( cbUrl, dataObj )
.post( flw_rave_options.cb_url, dataObj )
.success( function(data) {
var response = JSON.parse( data );
redirectUrl = response.redirect_url;

if ( redirectUrl === '' ) {

var responseMsg = ( res.tx.paymentType === 'account' ) ? res.tx.acctvalrespmsg : res.tx.vbvrespmessage;
jQuery( '#notice' ).text( responseMsg ).removeClass( existingClasses ).addClass( response.status );
jQuery( form )
.find( '#notice' )
.text( responseMsg )
.removeClass( function() {
return jQuery( form ).find( '#notice' ).attr( 'class' );
} )
.addClass( response.status );

} else {

Expand All @@ -106,21 +99,8 @@ var sendPaymentRequestResponse = function( res ) {
*/
var redirectTo = function( url ) {

if ( url !== '' ) {

if ( url ) {
location.href = url;

}

};

/**
* Returns existing classes on the #notice element
*
* @return string - Space separated lists of classes
*/
var existingClasses = function() {

return jQuery( '#notice' ).attr( 'class' );

};
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
exit;
}

if ( ! class_exists( 'FLW_Admin_Settings' ) ) {
if ( ! class_exists( 'FLW_Rave_Admin_Settings' ) ) {

/**
* Admin Settings class
*/
class FLW_Admin_Settings {
class FLW_Rave_Admin_Settings {

/**
* Class instance
Expand All @@ -33,8 +33,8 @@ class FLW_Admin_Settings {
private function __construct() {

// $this->flw_add_admin_menu();
add_action( 'admin_menu', array( $this, 'flw_add_admin_menu' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_menu', array( $this, 'flw_rave_add_admin_menu' ) );
add_action( 'admin_init', array( $this, 'flw_rave_register_settings' ) );
$this->init_settings();

}
Expand All @@ -44,16 +44,16 @@ private function __construct() {
*
* @return void
*/
public function register_settings() {
public function flw_rave_register_settings() {

register_setting( 'flw-flutterwave-pay-settings-group', 'flw_flutterwave_options' );
register_setting( 'flw-rave-settings-group', 'flw_rave_options' );

}

private function init_settings() {

if ( false == get_option( 'flw_flutterwave_options' ) ) {
update_option( 'flw_flutterwave_options', array() );
if ( false == get_option( 'flw_rave_options' ) ) {
update_option( 'flw_rave_options', array() );
}

}
Expand All @@ -67,7 +67,7 @@ private function init_settings() {
*/
public function get_option_value( $attr ) {

$options = get_option( 'flw_flutterwave_options' );
$options = get_option( 'flw_rave_options' );

if ( array_key_exists($attr, $options) ) {

Expand All @@ -86,7 +86,7 @@ public function get_option_value( $attr ) {
*/
public function is_public_key_present() {

$options = get_option( 'flw_flutterwave_options' );
$options = get_option( 'flw_rave_options' );

if ( false == $options ) return false;

Expand Down Expand Up @@ -115,16 +115,25 @@ public static function get_instance() {
* Add admin menu
* @return void
*/
public function flw_add_admin_menu() {
public function flw_rave_add_admin_menu() {

add_menu_page(
__( 'Flutterwave Pay', 'flw-flutterwave-pay' ),
'Flutterwave Pay',
__( 'Rave Settings Page', 'rave-pay' ),
'Rave',
'manage_options',
'flutterwave-pay',
array( $this, 'flw_admin_setting_page' ),
FLW_DIR_URL . 'assets/images/flutterwave-icon.png',
99
'rave-payment-forms',
array( $this, 'flw_rave_admin_setting_page' ),
FLW_DIR_URL . 'assets/images/rave-icon.jpg',
58
);

add_submenu_page(
'rave-payment-forms',
__( 'Rave Payment Forms Settings', 'rave-pay' ),
__( 'Settings', 'rave-pay' ),
'manage_options',
'rave-payment-forms',
array( $this, 'flw_rave_admin_setting_page' )
);

}
Expand All @@ -133,7 +142,7 @@ public function flw_add_admin_menu() {
* Admin page content
* @return void
*/
public function flw_admin_setting_page() {
public function flw_rave_admin_setting_page() {

include_once( FLW_DIR_PATH . 'views/admin-settings-page.php' );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php
/**
* Flutterwave Pay base class
* Rave base class
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! class_exists( 'FLW_Flutterwave_Pay' ) ) {
if ( ! class_exists( 'FLW_Rave_Pay' ) ) {

/**
* Main Plugin Class
*/
class FLW_Flutterwave_Pay {
class FLW_Rave_Pay {

private $plugin_name = 'flutterwave-pay';
private $plugin_name = 'rave-payment-forms';

/**
* Instance variable
Expand Down Expand Up @@ -44,13 +44,13 @@ function __construct() {
*/
private function include_files() {

require_once( FLW_DIR_PATH . 'includes/flutterwave-shortcode.php' );
require_once( FLW_DIR_PATH . 'includes/flutterwave-admin-settings.php' );
require_once( FLW_DIR_PATH . 'includes/flutterwave-payment-list-class.php' );
require_once( FLW_DIR_PATH . 'includes/rave-shortcode.php' );
require_once( FLW_DIR_PATH . 'includes/rave-admin-settings.php' );
require_once( FLW_DIR_PATH . 'includes/rave-payment-list-class.php' );
require_once( FLW_DIR_PATH . 'includes/vc-elements/simple-vc-pay-now-form.php' );

if ( is_admin() ) {
require_once( FLW_DIR_PATH . 'includes/flutterwave-tinymce-plugin-class.php' );
require_once( FLW_DIR_PATH . 'includes/rave-tinymce-plugin-class.php' );
}

}
Expand All @@ -65,10 +65,10 @@ private function init() {
global $admin_settings;
global $payment_list;

FLW_Shortcode::get_instance();
new FLW_Rave_Shortcode;

$payment_list = FLW_Payment_List::get_instance();
$admin_settings = FLW_Admin_Settings::get_instance();
$admin_settings = FLW_Rave_Admin_Settings::get_instance();
$payment_list = FLW_Rave_Payment_List::get_instance();

if ( is_admin() ) {
FLW_Tinymce_Plugin::get_instance();
Expand All @@ -84,12 +84,12 @@ private function init() {
*/
public function admin_notices() {

$options = get_option( 'flw_flutterwave_options' );
$options = get_option( 'flw_rave_options' );

if ( ! array_key_exists('public_key', $options ) || empty( $options['public_key'] ) ) {
echo '<div class="updated"><p>';
echo __( 'Flutterwave Pay is installed. - ', 'flutterwave-pay' );
echo "<a href=" . esc_url( add_query_arg( 'page', $this->plugin_name, admin_url( 'admin.php' ) ) ) . " class='button-primary'>" . __( 'Enter your Flutterwave Public Key to start accepting payments', 'flutterwave-pay' ) . "</a>";
echo __( 'Rave payment form plugin is installed. - ', 'rave-pay' );
echo "<a href=" . esc_url( add_query_arg( 'page', $this->plugin_name, admin_url( 'admin.php' ) ) ) . " class='button-primary'>" . __( 'Enter your Rave "Pay Button" Public Key to start accepting payments', 'rave' ) . "</a>";
echo '</p></div>';
}

Expand All @@ -104,7 +104,7 @@ public function process_payment() {

global $admin_settings;

check_ajax_referer( 'flw-flutterwave-pay-nonce', 'flw_sec_code' );
check_ajax_referer( 'flw-rave-pay-nonce', 'flw_sec_code' );

$response_code = ( $_POST['paymentType'] === 'account' ) ? $_POST['acctvalrespcode'] : $_POST['vbvrespcode'];
$status = ( $response_code == '00' ) ? 'successful' : 'failed';
Expand All @@ -119,10 +119,10 @@ public function process_payment() {
if ( ! is_wp_error( $payment_record_id )) {

$post_meta = array(
'_flw_payment_amount' => $_POST['amount'],
'_flw_payment_customer' => $_POST['customer']['email'],
'_flw_payment_status' => $status,
'_flw_payment_tx_ref' => $_POST['txRef'],
'_flw_rave_payment_amount' => $_POST['amount'],
'_flw_rave_payment_customer' => $_POST['customer']['email'],
'_flw_rave_payment_status' => $status,
'_flw_rave_payment_tx_ref' => $_POST['txRef'],
);

$this->add_post_meta( $payment_record_id, $post_meta );
Expand Down
Loading

0 comments on commit 69e444e

Please sign in to comment.