Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 27.24 KB | None | 0 0
  1. <?php
  2. /**
  3.  * WC wcEdpg1 Gateway Class.
  4.  * Built the wcEdpg1 method.
  5.  */
  6.  
  7. add_action('plugins_loaded', 'init_edebitdirect_Payment_Gateway', 1);
  8.  
  9. function init_edebitdirect_Payment_Gateway() {
  10.  
  11.     class edebitdirect extends WC_Payment_Gateway{
  12.  
  13.         /**
  14.          * Constructor for the gateway.
  15.          *
  16.          * @return void
  17.          */
  18.         public function __construct() {
  19.             global $woocommerce;
  20.             add_action('woocommerce_api_edebitdirect', 'api_check_edebitdirect');
  21.             $this->id             = 'edebitdirect';
  22.             $this->icon           = apply_filters( 'woocommerce_edebitdirect_icon', '' );
  23.             $this->has_fields     = false;
  24.             $this->method_title   = __( 'EdebitDirect', 'edebitdirect' );
  25.  
  26.             // Load the settings.
  27.             $this->init_form_fields();
  28.             $this->init_settings();
  29.             if ($this->settings['test_mode']=='no')
  30.                 wp_enqueue_script( 'edebitdirect-payments-script', plugins_url( '/dist/payments.min.js', __FILE__ ), array('jquery'), null, false  );
  31.             else
  32.                 wp_enqueue_script( 'edebitdirect-payments-script', plugins_url( '/dist/payments.sandbox.min.js', __FILE__ ), array('jquery'), null, false  );
  33.  
  34.             $this->title          = $this->settings['title'];
  35.             $payment_html = '<div class="col3-set" id="payment_html"><div class="col-1"><div class="woocommerce-billing-fields"><h3>'.$this->settings['description_'].'</h3>
  36.            <p class="form-row form-row-wide address-field validate-state validate-required woocommerce-validated" data-sort="80" data-o_class="form-row form-row-wide address-field validate-state">
  37.            <label for="check_number" class="">Check Number <abbr class="required" title="required">*</abbr></label>
  38.            <input type="text" class="input-text- number" autocomplete="off" value="" placeholder="Check Number" name="check_number" id="check_number"></p>
  39.            <p class="form-row form-row-wide address-field validate-state validate-required woocommerce-validated" data-sort="80" data-o_class="form-row form-row-wide address-field validate-state">
  40.            <label for="routing_number" class="">Routing Number <abbr class="required" title="required">*</abbr></label>
  41.            <input type="text" class="input-text- number" autocomplete="off" value="" placeholder="Routing Number" name="routing_number" id="routing_number"></p>
  42.            <p class="form-row form-row-wide address-field validate-state validate-required woocommerce-validated" data-sort="80" data-o_class="form-row form-row-wide address-field validate-state">
  43.            <label for="account_number" class="">Account Number <abbr class="required" title="required">*</abbr></label>
  44.            <input type="text" class="input-text- number" autocomplete="off" value="" placeholder="Account Number" name="account_number" id="account_number"></p>
  45.             <!--<p class="form-row form-row-wide address-field validate-state validate-required woocommerce-validated" data-sort="80" data-o_class="form-row form-row-wide address-field validate-state">
  46.             <input type="checkbox" style="float:left;margin:6px 6px 82px 6px;" class="" value="yes" name="certify_edebit" id="certify_edebit"><label style="color:orangered;" for="certify_edebit" class="">I certify that I am the authorized account holder for this bank account and hereby authorize the processing of this single draft payment payable to: Grand Traverse Holding LLC <abbr class="required" title="required">*</abbr></label></p>--></div></div></div>';
  47.             $this->description    = $payment_html;
  48.             $this->instructions       = $this->get_option( 'instructions' );
  49.             $this->enable_for_methods = $this->get_option( 'enable_for_methods', array() );
  50.             if(isset($_GET['code']))
  51.             {
  52.                 $redirect_uri = admin_url().'admin.php?page=wc-settings&tab=checkout&section=edebitdirect';
  53.                 $expire = time() + 60 * 60;
  54.                 setcookie('edebitdirect_code', $_GET['code'], $expire);
  55.                 setcookie('edebitdirect_state', $_GET['state'], $expire);
  56.                 wp_redirect($redirect_uri);
  57.                 exit();
  58.             }
  59.  
  60.             // Actions
  61.             add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
  62.             add_action('woocommerce_receipt_'. $this->id, array( $this, 'receipt_page' ) );
  63.  
  64.             add_action( 'woocommerce_order_details_after_order_table', array($this, 'eDebitDirect_display_cust_order_meta'));
  65.             add_action( 'woocommerce_before_order_itemmeta', array( $this, 'order_completion_before_order_itemmeta'));
  66.  
  67.  
  68.             // Actions.
  69.             if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) )
  70.                 add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ) );
  71.             else
  72.                 add_action( 'woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ) );
  73.  
  74.  
  75.         }
  76.  
  77.  
  78.         /* Admin Panel Options.*/
  79.         function admin_options() {
  80.             ?>
  81.             <h3><?php _e('EdebitDirect','edebitdirect'); ?></h3>
  82.             <table class="form-table">
  83.                 <?php $this->generate_settings_html(); ?>
  84.             </table> <?php
  85.         }
  86.  
  87.         /* Initialise Gateway Settings Form Fields. */
  88.         public function init_form_fields() {
  89.             global $woocommerce;
  90.  
  91.             $shipping_methods = array();
  92.             $redirect_uri = admin_url().'admin.php?page=wc-settings&tab=checkout&section=edebitdirect';
  93.             //$redirect_uri = admin_url();
  94.             global $woocommerce;
  95.  
  96.             $query = parse_url($url, PHP_URL_QUERY);
  97.  
  98.  
  99.  
  100.             $url = get_permalink(get_option('woocommerce_checkout_page_id'));
  101.             $query = parse_url($url, PHP_URL_QUERY);
  102.             if ($query) {
  103.                 $url .= '&wc-api=wc_edebitdirect';
  104.             } else {
  105.                 $url .= '?wc-api=wc_edebitdirect';
  106.             }
  107.             $iframe_callback = $url;
  108.  
  109.             if ( is_admin() )
  110.                 foreach ( $woocommerce->shipping->load_shipping_methods() as $method ) {
  111.                     $shipping_methods[ $method->id ] = $method->get_title();
  112.                 }
  113.  
  114.  
  115.             $this->icon = 'https://edebitdirect.com/static/img/logo.png';
  116.  
  117.             if($this->settings['test_mode']='no')
  118.             {
  119.                 $type_label = "LIVE ";
  120.                 $type_input = '_live';
  121.             }
  122.             else
  123.             {
  124.                 $type_label = "TEST ";
  125.                 $type_input = '';
  126.             }
  127.             $type_label = "";
  128.  
  129. /*
  130.             $curl = curl_init();
  131.  
  132.             curl_setopt($curl,CURLOPT_CUSTOMREQUEST,"GET");
  133.             curl_setopt($curl,CURLOPT_URL, $iframe_callback);
  134.             curl_setopt($curl,CURLOPT_HEADER,1);
  135.             curl_setopt($curl,CURLOPT_POST,0);
  136.             curl_setopt($curl,CURLOPT_USERAGENT,"User-Agent=Mozilla/5.0 Firefox/1.0.7");
  137.             curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
  138.             curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,1);
  139.             curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,1);
  140.             curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  141.             $_SITE_ANSWER = curl_exec($curl);
  142.             curl_close($curl);
  143.             if(!$_SITE_ANSWER)
  144.             {
  145.                 $https_status = '<div class="https_bad">Perhaps, your site is not configured to use https protocol</div>';
  146.             }
  147.             else
  148.             {
  149.                 $https_status = '<div class="https_good">HTTPS is enabled</div>';
  150.             }
  151. */
  152.             $https_status = '<div class="https_good">HTTPS is enabled</div>';
  153.  
  154.             $this->form_fields = array(
  155.                 'enabled' => array(
  156.                     'title' => __( 'Enable/Disable', 'edebitdirect' ),
  157.                     'type' => 'checkbox',
  158.                     'label' => __( 'Activate edebitdirect on Your web site', 'edebitdirect' ),
  159.                     'default' => 'no'
  160.                 ),
  161.                 'title' => array(
  162.                     'title' => __( 'Name', 'edebitdirect' ),
  163.                     'type' => 'text',
  164.                     'description' => __( 'This controls the title which the user sees during checkout.', 'edebitdirect' ),
  165.                     'desc_tip' => true,
  166.                     'default' => __( 'EdebitDirect', 'edebitdirect' )
  167.                 ),
  168.                 'description_' => array(
  169.                     'title' => __( 'Description', 'edebitdirect' ),
  170.                     'type' => 'textarea',
  171.                     'desc_tip' => true,
  172.                     'description' => __( 'This controls the description which the user sees during checkout.', 'edebitdirect' ),
  173.                     'default' => __( 'Desctiptions for edebitdirect.', 'edebitdirect' )
  174.                 ),
  175.                 'instructions' => array(
  176.                     'title' => __( 'Instructions', 'edebitdirect' ),
  177.                     'type' => 'textarea',
  178.                     'desc_tip' => true,
  179.                     'description' => __( 'Instructions that will be added to the thank you page.', 'edebitdirect' ),
  180.                     'default' => __( 'Instructions for edebitdirect.', 'edebitdirect' )
  181.                 ),
  182.                 'vendor_id'.$type_input => array(
  183.                     'title' => __( $type_label.'Client ID', 'edebitdirect' ),
  184.                     'type' => 'text',
  185.                     'desc_tip' => true,
  186.                     'description' => __( 'Your Client ID. You can get it on edebitdirect account. Tools -> Edit Client ID configuration', 'edebitdirect' ),
  187.                     'default' => __( '', 'edebitdirect' )
  188.                 ),
  189.                 'CallbackSecret'.$type_input => array(
  190.                     'title' => __( $type_label.'API KEY', 'edebitdirect' ),
  191.                     'type' => 'text',
  192.                     'desc_tip' => true,
  193.                     'description' => __( 'Your API KEY. You can get it on edebitdirect account. Tools -> Edit Checkout configuration', 'edebitdirect' ),
  194.                     'default' => __( '', 'edebitdirect' )
  195.                 ),
  196.                 /*'iframe_callback1234' => array(
  197.                     'title' => __( 'Callback URL: <b>'.$iframe_callback.'</b>', 'edebitdirect' ),
  198.                     'type' => 'title',
  199.                     'desc_tip' => true,
  200.                     'default' => $iframe_callback,
  201.                     'description' => 'Copy this Callback URL into <a href="https://wallet.edebitdirect/#/app/merchant/tools/checkout" target="_blank">https://wallet.edebitdirect/#/app/ merchant/tools/checkout</a>'
  202.                 ),*/
  203.                 /*
  204.                 'app_id' => array(
  205.                     'title' => __( 'Application ID', 'edebitdirect' ),
  206.                     'type' => 'text',
  207.                     'desc_tip' => true,
  208.                     'description' => __( 'Your Client-ID. You can get it on edebitdirect account.', 'edebitdirect' ),
  209.                     'default' => __( '', 'edebitdirect' )
  210.                 ),
  211.                 'app_key'.$type_input => array(
  212.                     'title' => __( $type_label.'Application Key', 'edebitdirect' ),
  213.                     'type' => 'text',
  214.                     'desc_tip' => true,
  215.                     'description' => __( 'Your Application Key. You can get it on edebitdirect account -> tools -> Add new', 'edebitdirect' ),
  216.                     'default' => __( '', 'edebitdirect' )
  217.                 ),
  218.                 'app_secret'.$type_input => array(
  219.                     'title' => __( $type_label.'Application Secret', 'edebitdirect' ),
  220.                     'type' => 'text',
  221.                     'desc_tip' => true,
  222.                     'description' => __( 'Your Application Secret. You can get it on edebitdirect account -> tools -> Add new', 'edebitdirect' ),
  223.                     'default' => __( '', 'edebitdirect' )
  224.                 ),
  225.                 */
  226.                 'test_mode' => array(
  227.                     'title' => __( 'Test Mode', 'edebitdirect' ),
  228.                     'type' => 'checkbox',
  229.                     'label' => __( 'Enable/Disable', 'edebitdirect' ),
  230.                     'default' => 'no'
  231.                 ),
  232. /*
  233.                 'get_history' => array(
  234.                 'title' => __( 'Download History <a href="#" class="export_edebitdirect" rel="xml">XML</a> <a href="#" class="export_edebitdirect" rel="doc">DOC</a> <a href="#" class="export_edebitdirect" rel="pdf">PDF</a>', 'edebitdirect_Io' ),
  235.                 'type' => 'title',
  236.                 'label' => __( 'Download History', 'edebitdirect_Io' ),
  237.                 'default' => 'no',
  238.                 'description' => ''
  239.                 ),
  240.  
  241.  
  242.                 'iframe_callback' => array(
  243.                     'title' => __( 'Payment callback : <b>'.$iframe_callback.'</b>', 'edebitdirect' ),
  244.                     'type' => 'title',
  245.                     'label' => __( '&nbsp;', 'edebitdirect' ),
  246.                     'default' => 'no',
  247.                     'description' => 'Copy this application callback URL into <a href="https://wallet.edebitdirect/#/app/merchant/tools/checkout" target="_blank">https://wallet.edebitdirect/#/app/merchant/tools/checkout</a>'
  248.                 ),
  249.  
  250.                 'app_callback_url' => array(
  251.                     'title' => __( 'Application callback : <b>'.$redirect_uri.'</b>', 'edebitdirect' ),
  252.                     'type' => 'title',
  253.                     'label' => __( '&nbsp;', 'edebitdirect' ),
  254.                     'default' => 'no',
  255.                     'description' => ''
  256.                 ),
  257. /*
  258.                 'https' => array(
  259.                     'title' => __( $https_status, 'edebitdirect' ),
  260.                     'type' => 'title',
  261.                     'label' => __( '', 'edebitdirect' ),
  262.                     'default' => 'no',
  263.                     'description' => ''
  264.                 ),
  265. */
  266.             );
  267.  
  268.         }
  269.  
  270.  
  271.  
  272.  
  273.         function process_payment($order_id){
  274.                 $order = new WC_Order($order_id);
  275.                 return array(
  276.                     'result' => 'success',
  277.                     'redirect'  => add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(woocommerce_get_page_id('pay'))))
  278.                 );
  279.         }
  280.  
  281.         public function receipt_page($order){
  282.                 echo $this->generate_form($order);
  283.         }
  284.  
  285.  
  286.         public function generate_form($order_id){
  287.  
  288.                 $order = new WC_Order( $order_id );
  289.                 global $woocommerce;
  290.  
  291.                 $args = array(
  292.                                 'amt'         => $order->order_total,
  293.                                 'ccy'         => get_woocommerce_currency(),
  294.                                 'order'       => $order_id,
  295.                                 'details'     => "$order_id",
  296.                                 'ext_details' => "$order_id",
  297.                                 'pay_way'     => 'EdebitDirect',
  298.                                 'return_url'  => $result_url,
  299.                                 'server_url'  => '',
  300.                             );
  301.                 $args_array = array();
  302.                 $expire = time()+60*60 * 24;
  303.                 setcookie('edebitdirect_order_number', $order_id, $expire);
  304.                 setcookie('edebitdirect_order_total', $order->order_total, $expire);
  305.                 $secr = rand(100000000,999999999);
  306.  
  307.                 update_post_meta($order_id, 'secr_edebitdirect', $secr);
  308.                 update_post_meta($order_id, 'secr_md5_edebitdirect', md5($secr));
  309.                 $memo = $order_id.'-'.md5($secr);
  310.  
  311.  
  312.                 if($this->settings['test_mode']=='no')
  313.                 {
  314.                     $domain = 'https://edebitdirect.com/app/api/v1/check/';
  315.                     $test=0;
  316.                 }
  317.                 else
  318.                 {
  319.                     $domain = 'https://dev.edebitdirect.com/app/api/v1/check/';
  320.                     $test=1;
  321.                 }
  322. //                $frame_url = $domain.'/payment-page?vendor_id='.$this->settings['vendor_id'].'&price='.$args['amt'].'&memo='.$memo.'&currency_type='.$args['ccy'].'';
  323.                 $frame_url = $domain;
  324.                 $email = $order->billing_email;
  325.                 $first_name = $order->billing_first_name;
  326.                 $last_name = $order->billing_last_name;
  327.                 $fullName = $first_name.' '.$last_name;
  328.                 $company = $order->billing_company;
  329.                 $address_1 = $order->billing_address_1;
  330.                 $address_2 = $order->billing_address_2;
  331.                 $city = $order->billing_city;
  332.                 $state = $order->billing_state;
  333.                 $postcode = $order->billing_postcode;
  334.                 $country = $order->billing_country;
  335.                 $phone = $order->billing_phone;
  336.                 $street = $address_1.' '.$address_2.' '.$country;
  337.  
  338.                 $check_number = get_post_meta($order_id, 'check_number', true);
  339.                 $routing_number = get_post_meta($order_id, 'routing_number', true);
  340.                 $account_number = get_post_meta($order_id, 'account_number', true);
  341.                 $vendor_id = $this->settings['vendor_id'];
  342.                 $callbackSecret = $this->settings['CallbackSecret'];
  343.  
  344.                 if(empty($vendor_id) || empty($callbackSecret)){
  345.                     $settings_url = admin_url('/admin.php?page=wc-settings&tab=checkout&section=edebitdirect');
  346.                     wp_die('Sorry, Your settings may not properly not configerd. <a href="'.$settings_url.'" target="_blank">Click to update</a>');
  347.                 }
  348.  
  349.  
  350.                 ini_set('display_errors', 1);
  351.                 ini_set('display_startup_errors', 1);
  352.                 error_reporting(E_ALL);
  353.  
  354.                 //API Url
  355.                 $url = $domain;
  356.  
  357.                 //Initiate cURL.
  358.                 $ch = curl_init($url);
  359.  
  360.                 //The JSON data.
  361.                 $jsonData = array(
  362.                   "customer_name"   => $fullName,
  363.                   "customer_street" => $street,
  364.                   "customer_city"   => $city,
  365.                   "customer_state"  => $state,
  366.                   "customer_zip"    => $postcode,
  367.                   "customer_phone"  => $phone,
  368.                   "customer_email"  => $email,
  369.                   "amount"          => $args['amt'],
  370.                   "check_number"    => $check_number,
  371.                   "routing_number"  => $routing_number,
  372.                   "account_number"  => $account_number,
  373.                   "is_customer_agree" => true
  374.                 );
  375.  
  376.                 $jsonDataEncoded = json_encode($jsonData);
  377.                 //echo $jsonDataEncoded; exit;
  378.  
  379.                 $header = array(
  380.                         "Authorization: apikey {$vendor_id}:{$callbackSecret}",
  381.                         "Content-Type: application/json",
  382.                         "Cache-Control: no-cache"
  383.                         );
  384.  
  385.                 //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  386.                 curl_setopt($ch, CURLOPT_POST, 1);
  387.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  388.                 curl_setopt($ch, CURLOPT_VERBOSE, 1);
  389.                 curl_setopt($ch, CURLOPT_HEADER, 1);
  390.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
  391.                 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  392.                 //Execute the request
  393.                 $result = curl_exec($ch);
  394.  
  395.                    $check_exp = explode('"check":', $result);
  396.                    if(!empty($check_exp[1])){
  397.                         $jsonCode = '{"check":'.$check_exp[1];
  398.                         $resultDec = json_decode($jsonCode, true);
  399.                         if(!empty($resultDec)){
  400.                             foreach ($resultDec['check'] as $key => $value) {
  401.                                 echo '<b>'.$key.' : </b>';
  402.                                 $no=1;
  403.                                 foreach ($value as $keys => $values) {
  404.                                     echo $no.'. '.$values.'<br>';
  405.                                     $no++;
  406.                                 }
  407.                             }
  408.                         }
  409.                         die('<p style="color:red;">Sorry, order canceled, please, re-check your checkout information!<p>');
  410.                    }
  411.  
  412.                 $checkoutUrl = '';
  413.                 if($result === FALSE) {
  414.                     die(curl_error($ch));
  415.                 } else {
  416.                     $location_exp = explode('Location: ', $result);
  417.                     if(!empty($location_exp[1])){
  418.                         update_post_meta($order_id, 'edebitdirect_location', trim($location_exp[1]));
  419.                     } else {
  420.                         die('<p style="color:red;">Sorry, something is going wrong, payment not completed. Please, try again!<p>');
  421.                     }
  422.                     $order_secr = get_post_meta($order_id, 'secr_edebitdirect', true);
  423.                     $secr_md5_edebitdirect = get_post_meta($order_id, 'secr_md5_edebitdirect', true);
  424.                     if($secr_md5_edebitdirect==md5($order_secr))
  425.                     {
  426.  
  427.                         //$order->update_status('completed');
  428.                         //$order->update_status('pending', __('After verify payment status will be completed', 'woocommerce'));
  429.                         $order->update_status('processing', __('Payment EXECUTED via edebitdirect', 'woocommerce'));
  430.                         //$order->add_order_note( __('Payment edebitdirect Approved: Transaction ID'.$order->order_key, 'woocommerce') );
  431.                         //$woocommerce->cart->empty_cart();
  432.                         //wp_send_json( array( 'status' => 'success', 'data' => 'payment ok' ) );
  433. //                        wp_die('payment ok');
  434.  
  435.                     }
  436.                     else
  437.                     {
  438.                         wp_die('payment hash fail');
  439.                     }
  440.  
  441.                     //print_r($order);
  442.  
  443.                     $checkoutUrl = get_permalink(woocommerce_get_page_id('pay')).'order-received/'.$order_id.'/?key='.$order->order_key;
  444.                     echo "<script>window.location.href = '".$checkoutUrl."';</script>";
  445.                    
  446.                 }
  447.  
  448.                 curl_close($ch);
  449.         }
  450.  
  451.  
  452.         public function eDebitDirect_display_cust_order_meta($order){
  453.             $edebitdirect_location = get_post_meta( $order->id, 'edebitdirect_location', true );
  454.             if(!empty($edebitdirect_location)){
  455.                 ini_set('display_errors', 1);
  456.                 ini_set('display_errors','on');
  457.                 ini_set('display_startup_errors', 1);
  458.                 error_reporting(E_ALL);
  459.  
  460.                 //API Url
  461.                 $url = trim($edebitdirect_location);
  462.  
  463.                 //Initiate cURL.
  464.                 $ch = curl_init($url);
  465.                 $vendor_id = $this->settings['vendor_id'];
  466.                 $callbackSecret = $this->settings['CallbackSecret'];
  467.  
  468.                 $header = array(
  469.                         "Authorization: apikey {$vendor_id}:{$callbackSecret}",
  470.                         "Content-Type: application/json",
  471.                         "Cache-Control: no-cache"
  472.                         );
  473. //                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  474.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  475.                 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  476.  
  477.                 //Execute the request
  478.                 $result = curl_exec($ch);
  479.                 $edebit_data = json_decode($result, true); ?>
  480.                     <table>
  481.                         <tbody>
  482.                             <tr>
  483.                                 <th scope="row">eDebitDirect Customer Name:</th>
  484.                                 <td>
  485.                                     <?php echo $edebit_data['customer_name']; ?>
  486.                                 </td>
  487.                             </tr>
  488.                             <tr>
  489.                                 <th scope="row">eDebitDirect Reference Number:</th>
  490.                                 <td>
  491.                                     <?php echo $edebit_data['reference_number']; ?>
  492.                                 </td>
  493.                             </tr>
  494.                             <tr>
  495.                                 <th scope="row">eDebitDirect Created Date</th>
  496.                                 <td>
  497.                                     <?php echo $edebit_data['created_date']; ?>
  498.                                 </td>
  499.                             </tr>
  500.                             <tr>
  501.                                 <th scope="row">eDebitDirect Status</th>
  502.                                 <td>
  503.                                     <?php echo $edebit_data['status']; ?>
  504.                                 </td>
  505.                             </tr>
  506.                         </tbody>
  507.                     </table>
  508.                 <?php
  509.             }
  510.            
  511.         }
  512.  
  513.         public function order_completion_before_order_itemmeta( $item_id ){
  514.             global $wpdb;
  515.  
  516.              $orderId = get_the_ID();
  517.              $edebitdirect_location = get_post_meta( $orderId, 'edebitdirect_location', true );
  518.             if(!empty($edebitdirect_location)){
  519.                 ini_set('display_errors', 1);
  520.                 ini_set('display_errors','on');
  521.                 ini_set('display_startup_errors', 1);
  522.                 error_reporting(E_ALL);
  523.  
  524.                 //API Url
  525.                 $url = trim($edebitdirect_location);
  526.  
  527.                 //Initiate cURL.
  528.                 $ch = curl_init($url);
  529.                 $vendor_id = $this->settings['vendor_id'];
  530.                 $callbackSecret = $this->settings['CallbackSecret'];
  531.  
  532.                 $header = array(
  533.                         "Authorization: apikey {$vendor_id}:{$callbackSecret}",
  534.                         "Content-Type: application/json",
  535.                         "Cache-Control: no-cache"
  536.                         );
  537.                 //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  538.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  539.                 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  540.  
  541.                 //Execute the request
  542.                 $result = curl_exec($ch);
  543.                 $edebit_data = json_decode($result, true); ?>
  544.                     <table>
  545.                         <tbody>
  546.                             <tr>
  547.                                 <td scope="row" colspan="2">eDebitDirect Customer Name:</td>
  548.                                 <td>
  549.                                     <?php echo $edebit_data['customer_name']; ?>
  550.                                 </td>
  551.                             </tr>
  552.                             <tr>
  553.                                 <td scope="row" colspan="2">eDebitDirect Reference Number:</td>
  554.                                 <td>
  555.                                     <?php echo $edebit_data['reference_number']; ?>
  556.                                 </td>
  557.                             </tr>
  558.                             <tr>
  559.                                 <td scope="row" colspan="2">eDebitDirect Created Date</td>
  560.                                 <td>
  561.                                     <?php echo $edebit_data['created_date']; ?>
  562.                                 </td>
  563.                             </tr>
  564.                             <tr>
  565.                                 <td scope="row" colspan="2">eDebitDirect Status</td>
  566.                                 <td>
  567.                                     <?php echo $edebit_data['status']; ?>
  568.                                 </td>
  569.                             </tr>
  570.                         </tbody>
  571.                     </table>
  572.                 <?php
  573.             }
  574.  
  575.         }
  576.  
  577.     }
  578.  
  579. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement