<commit_before><?php
/*
Plugin Name: WooCommerce Flutterwave Express Checkout Gateway
Plugin URI: http://flutterwave.com/
Description: A payment gateway for Flutterwave Express Checkout.
Version: 0.0.1
Author: <NAME>
Author URI: http://twitter.com/bosunolanrewaju
  Copyright: © 2016 <NAME>.
  License: MIT License
*/

define( 'FLW_PLUGIN_FILE', __FILE__ );

add_action('plugins_loaded', 'flw_woocommerce_flutterwave_init', 0);

function flw_woocommerce_flutterwave_init() {

  if ( !class_exists( 'WC_Payment_Gateway' ) ) return;

  /**
   * Gateway class
   */
  class FLW_WC_Payment_Gateway extends WC_Payment_Gateway {

    /**
     * Constructor
     *
     * @return void
     */
    public function __construct() {

      $this->id = 'flutterwave';
      $this->icon = null;
      $this->has_fields         = false;
      $this->method_title       = __( 'Flutterwave Pay', 'flw-payments' );
      $this->method_description = __( 'Flutterwave Payment Gateway', 'flw-payments' );
      $this->supports           = array(
        'products',
      );

      $this->init_form_fields();
      $this->init_settings();

      $this->title        = __( 'Bank Account or Credit/Debit Cards', 'flw-payments' );
      $this->description  = __( 'Pay with your bank account or credit/debit card', 'flw-payments' );
      $this->enabled      = $this->get_option( 'enabled' );
      $this->public_key   = $this->get_option( 'public_key' );

      add_action( 'admin_notices', array( $this, 'admin_notices' ) );
      add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));

      if ( is_admin() ) {
        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
      }

      $this->load_scripts();
    }

    /**
     * Initial gateway settings form fields
     *
     * @return void
     */
    public function init_form_fields() {

      $this->form_fields = array(

        'enabled' => array(
          'title'       => __( 'Enable/Disable', 'flw-payments' ),
          'label'       => __( 'Enable Flutterwave Express Checkout', 'flw-payments' ),
          'type'        => 'checkbox',
          'description' => __( 'Enable Flutterwave Express Checkout as a payment option on the checkout page', 'flw-payments' ),
          'default'     => 'no',
          'desc_tip'    => true
        ),
        'public_key' => array(
          'title'       => __( 'Integration Public Key', 'flw-payments' ),
          'type'        => 'text',
          'description' => __( 'Enter your Public Key here', 'flw-payments' ),
          'default'     => ''
        ),

      );

    }

    /**
     * Process payment at checkout
     *
     * @return int $order_id
     */
    public function process_payment( $order_id ) {

      $order = wc_get_order( $order_id );

      return array(
        'result'   => 'success',
        'redirect' => $order->get_checkout_payment_url( true )
      );

    }

    /**
     * Handles admin notices
     *
     * @return void
     */
    public function admin_notices() {

      if ( 'no' == $this->enabled ) {
        return;
      }

      /**
       * Check if public key is provided
       */
      if ( ! ( $this->public_key ) ) {

        echo '<div class="error"><p>';
        echo sprintf(
          'Provide your Flutterwave integration public key <a href="%s">here</a> to be able to use the WooCommerce Flutterwave Express Checkout plugin.',
           admin_url( 'admin.php?page=wc-settings&tab=checkout&section=flutterwave' )
         );
        echo '</p></div>';
        return;
      }

    }

    /**
     * Checkout receipt page
     *
     * @return void
     */
    public function receipt_page( $order ) {

      $order = wc_get_order( $order );

      echo '<p>'.__('Thank you for your order, please click the button below to pay with Flutterwave Express Checkout.', 'mrova').'</p>';
      echo '<script type="text/javascript" src="https://flutterv3.herokuapp.com/flwv3-pug/getpaid/api/flwpbf-inline.js"></script>';

      echo '<button class="button alt" id="flw-pay-now-button">Pay Now</button> ';
      echo ' <a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">';
      echo __('Cancel order &amp; restore cart', 'flw-payments') . '</a>';

    }

    /**
     * Loads (enqueue) static files (js & css) for the checkout page
     *
     * @return void
     */
    public function load_scripts() {

      if ( ! is_checkout_pay_page() ) return;

      wp_enqueue_script( 'flwpbf_inline_js', 'https://flutterv3.herokuapp.com/flwv3-pug/getpaid/api/flwpbf-inline.js', array(), '1.0.0', true );
      wp_enqueue_script( 'flw_js', plugins_url( 'assets/js/flw.js', FLW_PLUGIN_FILE ), array('flwpbf_inline_js'), '1.0.0', true );

      $payment_args = array(
        'p_key' => $this->public_key
      );

      if ( get_query_var( 'order-pay' ) ) {

        $order_key = urldecode( $_REQUEST['key'] );
        $order_id  = absint( get_query_var( 'order-pay' ) );
        $order     = wc_get_order( $order_id );
        $txnref    = $order_id . '_' . time();
        $amount    = $order->order_total;
        $email     = $order->billing_email;

        if ( $order->order_key == $order_key ) {

          $payment_args['email']   = $email;
          $payment_args['amount']  = $amount;
          $payment_args['txnref']  = $txnref;<commit_msg>Change inline-js CDN url<commit_after><?php
/*
Plugin Name: WooCommerce Flutterwave Express Checkout Gateway
Plugin URI: http://flutterwave.com/
Description: A payment gateway for Flutterwave Express Checkout.
Version: 0.0.1
Author: <NAME>
Author URI: http://twitter.com/bosunolanrewaju
  Copyright: © 2016 <NAME>.
  License: MIT License
*/

define( 'FLW_PLUGIN_FILE', __FILE__ );

add_action('plugins_loaded', 'flw_woocommerce_flutterwave_init', 0);

function flw_woocommerce_flutterwave_init() {

  if ( !class_exists( 'WC_Payment_Gateway' ) ) return;

  /**
   * Gateway class
   */
  class FLW_WC_Payment_Gateway extends WC_Payment_Gateway {

    /**
     * Constructor
     *
     * @return void
     */
    public function __construct() {

      $this->id = 'flutterwave';
      $this->icon = null;
      $this->has_fields         = false;
      $this->method_title       = __( 'Flutterwave Pay', 'flw-payments' );
      $this->method_description = __( 'Flutterwave Payment Gateway', 'flw-payments' );
      $this->supports           = array(
        'products',
      );

      $this->init_form_fields();
      $this->init_settings();

      $this->title        = __( 'Bank Account or Credit/Debit Cards', 'flw-payments' );
      $this->description  = __( 'Pay with your bank account or credit/debit card', 'flw-payments' );
      $this->enabled      = $this->get_option( 'enabled' );
      $this->public_key   = $this->get_option( 'public_key' );

      add_action( 'admin_notices', array( $this, 'admin_notices' ) );
      add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));

      if ( is_admin() ) {
        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
      }

      $this->load_scripts();
    }

    /**
     * Initial gateway settings form fields
     *
     * @return void
     */
    public function init_form_fields() {

      $this->form_fields = array(

        'enabled' => array(
          'title'       => __( 'Enable/Disable', 'flw-payments' ),
          'label'       => __( 'Enable Flutterwave Express Checkout', 'flw-payments' ),
          'type'        => 'checkbox',
          'description' => __( 'Enable Flutterwave Express Checkout as a payment option on the checkout page', 'flw-payments' ),
          'default'     => 'no',
          'desc_tip'    => true
        ),
        'public_key' => array(
          'title'       => __( 'Integration Public Key', 'flw-payments' ),
          'type'        => 'text',
          'description' => __( 'Enter your Public Key here', 'flw-payments' ),
          'default'     => ''
        ),

      );

    }

    /**
     * Process payment at checkout
     *
     * @return int $order_id
     */
    public function process_payment( $order_id ) {

      $order = wc_get_order( $order_id );

      return array(
        'result'   => 'success',
        'redirect' => $order->get_checkout_payment_url( true )
      );

    }

    /**
     * Handles admin notices
     *
     * @return void
     */
    public function admin_notices() {

      if ( 'no' == $this->enabled ) {
        return;
      }

      /**
       * Check if public key is provided
       */
      if ( ! ( $this->public_key ) ) {

        echo '<div class="error"><p>';
        echo sprintf(
          'Provide your Flutterwave integration public key <a href="%s">here</a> to be able to use the WooCommerce Flutterwave Express Checkout plugin.',
           admin_url( 'admin.php?page=wc-settings&tab=checkout&section=flutterwave' )
         );
        echo '</p></div>';
        return;
      }

    }

    /**
     * Checkout receipt page
     *
     * @return void
     */
    public function receipt_page( $order ) {

      $order = wc_get_order( $order );

      echo '<p>'.__('Thank you for your order, please click the button below to pay with Flutterwave Express Checkout.', 'mrova').'</p>';
      echo '<script type="text/javascript" src="https://flutterv3.herokuapp.com/flwv3-pug/getpaid/api/flwpbf-inline.js"></script>';

      echo '<button class="button alt" id="flw-pay-now-button">Pay Now</button> ';
      echo ' <a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">';
      echo __('Cancel order &amp; restore cart', 'flw-payments') . '</a>';

    }

    /**
     * Loads (enqueue) static files (js & css) for the checkout page
     *
     * @return void
     */
    public function load_scripts() {

      if ( ! is_checkout_pay_page() ) return;

      wp_enqueue_script( 'flwpbf_inline_js', 'http://flw-pms-dev.eu-west-1.elasticbeanstalk.com/flwv3-pug/getpaid/api/flwpbf-inline.js', array(), '1.0.0', true );
      wp_enqueue_script( 'flw_js', plugins_url( 'assets/js/flw.js', FLW_PLUGIN_FILE ), array('flwpbf_inline_js'), '1.0.0', true );

      $payment_args = array(
        'p_key' => $this->public_key
      );

      if ( get_query_var( 'order-pay' ) ) {

        $order_key = urldecode( $_REQUEST['key'] );
        $order_id  = absint( get_query_var( 'order-pay' ) );
        $order     = wc_get_order( $order_id );
        $txnref    = $order_id . '_' . time();
        $amount    = $order->order_total;
        $email     = $order->billing_email;

        if ( $order->order_key == $order_key ) {

          $payment_args['email']   = $email;
          $payment_args['amount']  = $amount;
          $payment_args['txnref']  = $txnref;
{'fraction_non_alphanumeric': 0.15158517423052037, 'fraction_numerical': 0.0033274794343284963, 'mean_word_length': 2.377028714107366, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 117, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5496835', 'n_tokens_mistral': 3598, 'n_tokens_neox': 3514, 'n_words': 738}