Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Conversation opened. 1 unread message.
- Skip to content
- Using Gmail with screen readers
- Click here to enable desktop notifications for Gmail. Learn more Hide
- More
- 1 of 22,559
- (no subject)
- Inbox
- x
- manish rajput
- Attachments1:11 PM (4 minutes ago)
- to me
- Attachments area
- Click here to Reply or Forward
- 5.85 GB (39%) of 15 GB used
- Manage
- Terms - Privacy
- Last account activity: 2 hours ago
- Details
- manish rajput's profile photo
- manish rajput
- Show details
- <?php
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
- /**
- * Cash on Delivery Gateway
- *
- * Provides a Cash on Delivery Payment Gateway.
- *
- * @class WC_Gateway_COD
- * @extends WC_Payment_Gateway
- * @version 2.0.0
- * @package WooCommerce/Classes/Payment
- * @author Patrick Garman
- */
- class WC_Gateway_COD extends WC_Payment_Gateway {
- /**
- * Constructor for the gateway.
- *
- * @access public
- * @return void
- */
- function __construct() {
- $this->id = 'cod';
- $this->icon = apply_filters( 'woocommerce_cod_icon', '' );
- $this->method_title = __( 'Cash on Delivery', 'woocommerce' );
- $this->has_fields = false;
- // Load the settings
- $this->init_form_fields();
- $this->init_settings();
- // Get settings
- $this->title = $this->get_option( 'title' );
- $this->description = $this->get_option( 'description' );
- $this->instructions = $this->get_option( 'instructions' );
- $this->enable_for_methods = $this->get_option( 'enable_for_methods', array() );
- add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
- add_action( 'woocommerce_thankyou_cod', array( $this, 'thankyou' ) );
- }
- /*******api Function************/
- function verify_student($data,$access_token) {
- //session_start();
- $url="http://stg.thegateacademy.info:8080/api/subjectpack/GetStudentDetails/?param=".$data;
- $access_token=trim($access_token);
- if($access_token==""){
- $authorization="Authorization: bearer 8Fyqo27_8n7HE8rq5tPpdlwy-laYwCMCuL21pBLKze-pTqPxUiJgVGbW8vraaD706D0ZHraCBQjEgvTDt0rRJOrltDVo4RcUI1muOO60icno3K9xw8uNZfyr_uM9-wvn_2D88MR2Z0wVCsV9ubAXI7SxEaOPR20M_-Six7-KGVpq83ViwRUWHzuOfNd4fMdxgzUWH043Llgg4XmQV-F8TklGAIpS6J_JnyM7hRCfz_buvpDI-REQC2qKaLNbPDl85nXGoLKxnK3F-G7N3VV5wcmJQyBS1F7gQkm8EcXdMf-WImEdTw7Q9XaXjnhqFSWlba6oWR1isPdxTOu0CoJOhYuTnIxQgtIuXlat5MqTTZzlh91tPYZqTDDK_hdWiyL6BqMEA9tPq9fPkDxSmwt8EC_bUngZua6iOSlLBSwv2B2BpCGDp-hD443tAOEZBWIJKeVP6Y9sdpREACl_TFnxB3UmsdFgyVa6L21jSnQhXkVkBer1kESZB2nFjPwvq4F86HRE2AHRfu4dkLMRlwXwwHtHzrec2yR3v14ftYqaQW3Pv7LGUlnwmHzNuyu5Hd0aBa5UzILWBJmHQaX9FntejQ";
- }
- else {$authorization="Authorization: bearer ".$access_token;}
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml' , $authorization ));
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- // curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
- //$result = curl_exec($ch);
- $output = curl_exec($ch);
- //return $output;
- if ($output === FALSE) {
- echo "cURL Error: " . curl_error($ch);
- exit;
- }
- curl_close($ch);
- $obj =json_decode($output);
- $verification =$obj->{'StudentExists'};
- $phone= $obj->{'PhoneNumber'};
- $roll_no= $obj->{'RollNumber'};
- $st_name= $obj->{'StudentName'};
- $st_mail=$obj->{'Email'};
- $_SESSION['st_phone']=$phone;
- $_SESSION['st_rollno']=$roll_no;
- $_SESSION['st_mail']=$st_mail;
- $_SESSION['st_name']=$st_name;
- $str = explode(" ",$_SESSION['st_name']);
- $_SESSION['f_name']=$str[0];
- $_SESSION['l_name']=$str[1];
- return $verification;
- }
- function add_student_checkout_detail($fields_string) {
- session_start();
- global $wpdb;
- $access_token=$this->get_access_token();
- $url="http://stg.thegateacademy.info:8080/api/subjectpack/AddStudentCourse";
- $authorization="Authorization: bearer ".$access_token;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded' , $authorization ));
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POST, true); // tell curl you want to post something
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); // define what you want to post
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
- //$result = curl_exec($ch);
- $output = curl_exec($ch);
- $wpdb->insert( 'tga_request_api',
- array(
- 'string_passed' => $fields_string,
- 'output' => $output
- )
- );
- return $output;
- }
- function get_access_token()
- {
- $access_token="";
- date_default_timezone_set("Asia/Calcutta");
- $current_timestamp=time();
- if(get_option( "expirein")){
- if(get_option( "expirein")<=$current_timestamp){
- $url="http://stg.thegateacademy.info:8080/token";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS,"grant_type=password&username=subjectpack&password=Abcd123$");
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
- $output = curl_exec($ch);
- if ($output === FALSE) {
- echo "cURL Error: " . curl_error($ch);
- exit;
- }
- curl_close($ch);
- $obj =json_decode($output);
- // print_r($obj);
- $access_token= $obj->{'access_token'};
- $token_type= $obj->{'token_type'};
- $expirein= $obj->{'expirein'};
- update_option( "access_token", $access_token);
- update_option( "token_type", $token_type);
- update_option( "expirein", $expirein);
- }
- else {
- $access_token=get_option( "access_token");
- }
- }
- else
- {
- $url="http://stg.thegateacademy.info:8080/token";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS,"grant_type=password&username=subjectpack&password=Abcd123$");
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
- $output = curl_exec($ch);
- if ($output === FALSE) {
- echo "cURL Error: " . curl_error($ch);
- exit;
- }
- curl_close($ch);
- $obj =json_decode($output);
- // print_r($obj);
- $access_token= $obj->{'access_token'};
- $token_type= $obj->{'token_type'};
- $expires_in= strtotime($obj->{'.expires'});
- update_option( "access_token", $access_token);
- update_option( "token_type", $token_type);
- update_option( "expires_in", $expires_in);
- }
- return $access_token;
- }
- function get_stream_code($stream)
- {
- switch($stream){
- case "Civil Engineering": $stream_code="CE";break;
- case "Computer Science Engineering": $stream_code="CS & IT";break;
- case "Electrical Engineering": $stream_code="EEE";break;
- case "Electronics & Communication Engineering": $stream_code="ECE";break;
- case "Electronics & Communication Engineering": $stream_code="ECE";break;
- case "Electronics & Communication Engineering": $stream_code="ECE";break;
- case "Instrumentation Engineering": $stream_code="IN";break;
- case "Mechanical Engineering": $stream_code="ME";break;
- case "Monthaly Subscription Pack": $stream_code="SUB";break;
- }
- return $stream_code;
- }
- function get_eluctureCode($str)
- {
- switch($str){
- case "Online": $Code="OL";break;
- case "dvd": $Code="DVD";break;
- case "N/A": $Code="NA";break;
- case "Tablet": $Code="TAB";break;
- case "SDcard": $Code="SDC";break;
- case "Calling Tablet": $Code="CALTAB";break;
- case "Samsung Tablet": $Code="SAMTAB";break;
- case "tabGATE": $Code="TABG";break;
- case "USB": $Code="USB";break;
- }
- return $Code;
- }
- function get_testSeriesCode($str)
- {
- switch($str){
- case "Online": $Code="OL";break;
- }
- return $Code;
- }
- function apiSmcInteratio($ord_id){
- $order = new WC_Order($ord_id);
- date_default_timezone_set("Asia/Calcutta");
- $date=date("m-d-Y");
- $items = $order->get_items();
- $Stream=$order->order_custom_fields['Stream'][0];
- $stream_code=$this->get_stream_code($Stream);
- if(isset($order->order_custom_fields['Mode of E-Lectures'][0])){
- $Electure=$order->order_custom_fields['Mode of E-Lectures'][0];
- $ElectureType= $this->get_eluctureCode($Electure);
- }
- else {$ElectureType= "";}
- if(isset($order->order_custom_fields['Mode of Test Series'][0])){
- $TestSeries=$order->order_custom_fields['Mode of Test Series'][0];
- $TestSeriesType= $this->get_testSeriesCode($TestSeries);
- }
- else {$TestSeriesType= "";}
- $tar_year="";
- foreach ( $items as $item ) {
- $product_name = $item['name'];
- $product_id = $item['product_id'];
- if(isset($item['pa_gate-target-year'])){
- $tar_year= $item['pa_gate-target-year'];
- $tar_year=preg_replace("/[^0-9]/","", $tar_year);
- $ValidityDate="02-28-".$tar_year;
- }
- elseif(isset($item['Yearly Subscription'])){
- $tar_year= $item['Yearly Subscription'];
- $tar_year=preg_replace("/[^0-9]/","", $tar_year);
- $ValidityDate="02-28-".$tar_year;
- }
- else{
- $tar_year=preg_replace("/[^0-9]/","","Target Year 2017");
- $ValidityDate="02-28-".$tar_year;
- }
- $sub_code= rwmb_meta( "sub_code",'type=text',$product_id);
- $BookType=rwmb_meta( "BookType",'type=select',$product_id);
- if($BookType=="NA"){$BookType="";}
- //print_r($item);
- if (array_key_exists("Monthly Package", $item))
- {
- $month=preg_replace("/[^0-9]/","",$item['Monthly Package']);
- $sub_code=$sub_code.$month;
- $timestamp1 = strtotime(date("y-m-d"))+(2592000*$month);
- $ValidityDate=gmdate("m-d-Y", $timestamp1);
- $tar_year=preg_replace("/[^0-9]/","","Target Year 2017");
- }
- $product_cats = wp_get_post_terms( $product_id, 'product_cat' );
- $i=0;
- while($product_cats){
- $single_cat = array_shift( $product_cats );
- $cat_array[$i] =$single_cat->slug;
- $cat_id_array[$i] =$single_cat->id;
- $i++;
- }
- $res_code=$_REQUEST['pgRespCode'];
- /*if($order->payment_method_title!="Cash on Delivery" && $sub_code!=""){*/
- if(1){
- $paymentMode="Net Banking";
- $transaction_key=$order->order_key;
- $pi=0;
- $pterms = get_the_terms( $product_id, 'product_cat' );
- $micropack=0;
- foreach ($pterms as $pterm) {
- if($pterm->name=="micropack"){$micropack=1;break;}
- }
- if($micropack){
- $TestSeriesType='OL';
- $ElectureType='OL';
- }
- if($order->payment_method_title=="Net Banking"){$paymentMode="Net Banking";}
- elseif($order->payment_method_title=="Credit Card"){$paymentMode="Credit Card";}
- else{$paymentMode="Debit Card";}
- $fields = array(
- 'StudentName' =>urlencode( $order->billing_first_name." ".$order->billing_last_name),
- 'PhoneNumber' =>urlencode( $order->billing_phone),
- 'EmailId' => urlencode($order->billing_email),
- 'CourseCode' => urlencode($sub_code),
- 'StreamCode' => urlencode($stream_code),
- 'ExamTargetYear' => urlencode( $tar_year),
- 'ElectureType' => urlencode($ElectureType),
- 'TestSeriesType' => urlencode($TestSeriesType),
- 'BookType' => urlencode($BookType),
- 'AdmissionDate' => urlencode($date),
- 'CourseFees' => urlencode($order->order_total),
- 'DiscountAmount' =>urlencode($order->order_discount),
- 'TransactionID' => urlencode($transaction_key),
- 'PaymentMode' =>urlencode($paymentMode),
- 'ValidityDate' =>urlencode($ValidityDate)
- );
- $fields_string="";
- //url-ify the data for the POST
- foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
- trim($fields_string, ' ');
- $fields_string=rtrim($fields_string, '&');
- $out_json_string=$this->add_student_checkout_detail($fields_string);
- }
- }
- }
- /********End Api Integration***********/
- /**
- * Admin Panel Options
- * - Options for bits like 'title' and availability on a country-by-country basis
- *
- * @access public
- * @return void
- */
- function admin_options() {
- ?>
- <h3><?php _e('Cash on Delivery','woocommerce'); ?></h3>
- <p><?php _e('Have your customers pay with cash (or by other means) upon delivery.', 'woocommerce' ); ?></p>
- <table class="form-table">
- <?php $this->generate_settings_html(); ?>
- </table> <?php
- }
- /**
- * Initialise Gateway Settings Form Fields
- *
- * @access public
- * @return void
- */
- function init_form_fields() {
- global $woocommerce;
- $shipping_methods = array();
- if ( is_admin() )
- foreach ( $woocommerce->shipping->load_shipping_methods() as $method ) {
- $shipping_methods[ $method->id ] = $method->get_title();
- }
- $this->form_fields = array(
- 'enabled' => array(
- 'title' => __( 'Enable COD', 'woocommerce' ),
- 'label' => __( 'Enable Cash on Delivery', 'woocommerce' ),
- 'type' => 'checkbox',
- 'description' => '',
- 'default' => 'no'
- ),
- 'title' => array(
- 'title' => __( 'Title', 'woocommerce' ),
- 'type' => 'text',
- 'description' => __( 'Payment method title that the customer will see on your website.', 'woocommerce' ),
- 'default' => __( 'Cash on Delivery', 'woocommerce' ),
- 'desc_tip' => true,
- ),
- 'description' => array(
- 'title' => __( 'Description', 'woocommerce' ),
- 'type' => 'textarea',
- 'description' => __( 'Payment method description that the customer will see on your website.', 'woocommerce' ),
- 'default' => __( 'Pay with cash upon delivery.', 'woocommerce' ),
- ),
- 'instructions' => array(
- 'title' => __( 'Instructions', 'woocommerce' ),
- 'type' => 'textarea',
- 'description' => __( 'Instructions that will be added to the thank you page.', 'woocommerce' ),
- 'default' => __( 'Pay with cash upon delivery.', 'woocommerce' )
- ),
- 'enable_for_methods' => array(
- 'title' => __( 'Enable for shipping methods', 'woocommerce' ),
- 'type' => 'multiselect',
- 'class' => 'chosen_select',
- 'css' => 'width: 450px;',
- 'default' => '',
- 'description' => __( 'If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.', 'woocommerce' ),
- 'options' => $shipping_methods,
- 'desc_tip' => true,
- )
- );
- }
- /**
- * Check If The Gateway Is Available For Use
- *
- * @access public
- * @return bool
- */
- function is_available() {
- global $woocommerce;
- if ( ! empty( $this->enable_for_methods ) ) {
- if ( is_page( woocommerce_get_page_id( 'pay' ) ) ) {
- $order_id = (int) $_GET['order_id'];
- $order = new WC_Order( $order_id );
- if ( ! $order->shipping_method )
- return false;
- $chosen_method = $order->shipping_method;
- } elseif ( empty( $woocommerce->session->chosen_shipping_method ) ) {
- return false;
- } else {
- $chosen_method = $woocommerce->session->chosen_shipping_method;
- }
- $found = false;
- foreach ( $this->enable_for_methods as $method_id ) {
- if ( strpos( $chosen_method, $method_id ) === 0 ) {
- $found = true;
- break;
- }
- }
- if ( ! $found )
- return false;
- }
- return parent::is_available();
- }
- /**
- * Process the payment and return the result
- *
- * @access public
- * @param int $order_id
- * @return array
- */
- function process_payment ($order_id) {
- global $woocommerce;
- $order = new WC_Order( $order_id );
- // Mark as on-hold (we're awaiting the cheque)
- $order->update_status('on-hold', __( 'Payment to be made upon delivery.', 'woocommerce' ));
- // Reduce stock levels
- $order->reduce_order_stock();
- // Remove cart
- $woocommerce->cart->empty_cart();
- $this->apiSmcInteratio($order_id);
- // Return thankyou redirect
- return array(
- 'result' => 'success',
- 'redirect' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(woocommerce_get_page_id('thanks'))))
- );
- }
- /**
- * Output for the order received page.
- *
- * @access public
- * @return void
- */
- function thankyou() {
- echo $this->instructions != '' ? wpautop( $this->instructions ) : '';
- }
- }
- class-wc-gateway-cod.php
- Displaying class-wc-gateway-cod.php.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement