diff --git a/assets/img/logo-1.png b/assets/img/logo-1.png new file mode 100644 index 0000000..b8d1092 Binary files /dev/null and b/assets/img/logo-1.png differ diff --git a/assets/img/logo.png b/assets/img/logo.png new file mode 100644 index 0000000..e608b7a Binary files /dev/null and b/assets/img/logo.png differ diff --git a/assets/img/logo_back.png b/assets/img/logo_back.png new file mode 100644 index 0000000..b8d1092 Binary files /dev/null and b/assets/img/logo_back.png differ diff --git a/class-wc-tap-blocks-support.php b/class-wc-tap-blocks-support.php new file mode 100644 index 0000000..3d854ca --- /dev/null +++ b/class-wc-tap-blocks-support.php @@ -0,0 +1,103 @@ +asset_api = $asset_api; + } + + /** + * Initializes the payment method type. + */ + public function initialize() { + $this->settings = get_option( 'woocommerce_tap_settings', [] ); + } + + /** + * Returns if this payment method should be active. If false, the scripts will not be enqueued. + * + * @return boolean + */ + public function is_active() { + return filter_var( $this->get_setting( 'enabled', false ), FILTER_VALIDATE_BOOLEAN ); + } + + /** + * Returns an array of scripts/handles to be registered for this payment method. + * + * @return array + */ + public function get_payment_method_script_handles() { + $dependencies = []; + wp_register_script( 'woocommerce_wc_payment_method_tap', + plugins_url('wc-payment-method-tap.js', __FILE__ ), + array_merge([], $dependencies ), + '', + true + ); + return ['woocommerce_wc_payment_method_tap']; + } + + /** + * Returns an array of key=>value pairs of data made available to the payment methods script. + * + * @return array + */ + public function get_payment_method_data() { + return [ + 'title' => $this->get_setting( 'title' ), + 'description' => $this->get_setting( 'description' ), + 'supports' => $this->get_supported_features(), + ]; + } + + /** + * Returns an array of supported features. + * + * @return string[] + */ + public function get_supported_features() { + $gateway = new WC_Tap_Gateway(); + $features = array_filter( $gateway->supports, array( $gateway, 'supports' ) ); + + /** + * Filter to control what features are available for each payment gateway. + * + * @since 4.4.0 + * + * @example See docs/examples/payment-gateways-features-list.md + * + * @param array $features List of supported features. + * @param string $name Gateway name. + * @return array Updated list of supported features. + */ + return apply_filters( '__experimental_woocommerce_blocks_payment_gateway_features_list', $features, $this->get_name() ); + } +} diff --git a/taap.js b/taap.js new file mode 100644 index 0000000..4d095ad --- /dev/null +++ b/taap.js @@ -0,0 +1,174 @@ +jQuery(document).ready(function(){ + var live_public_key = jQuery("#live_public_key").val(); + var testmode = jQuery("#testmode").val(); + if (testmode == true) { + var active_pk = jQuery("#test_public_key").val(); + }else{ + var active_pk = jQuery("#publishable_key").val(); + } + + var tmode = jQuery("#payment_mode").val(); + var amount = jQuery("#amount").val(); + var save_card = jQuery("#save_card").val() + var Ui_language = jQuery("#ui_language").val(); + if( Ui_language == 'english'){ + Ui_language_val = 'en'; + }else{ + Ui_language_val = 'ar'; + } + + if( save_card == 'no') { + save_card_val = false; + }else { + save_card_val = true; + } + + var currency = jQuery("#currency").val(); + var billing_first_name = jQuery("#billing_first_name").val(); + var customer_user_id = jQuery("#customer_user_id").val(); + var billing_last_name = jQuery("#billing_last_name").val(); + var billing_email = jQuery("#billing_email").val(); + var billing_phone = jQuery("#billing_phone").val(); + var country_code = jQuery("#countrycode").val(); + + console.log(country_code); + + var items_values = []; + + jQuery('input[class$="items_bulk"]').each(function() { + items_values.push({ + 'id': jQuery(this).attr('data-item-product-id'), + 'name': jQuery(this).attr('data-name'), + 'description': '', + 'quantity': jQuery(this).attr('data-quantity'), + 'amount_per_unit': jQuery(this).attr('data-sale-price'), + 'discount': { + 'type': 'P', + 'value': '10%' + }, + 'total_amount': jQuery(this).attr('data-product-total-amount') + }); + }); + + if (tmode == 'authorize') { + var transaction_mode = { + mode: 'authorize', + authorize:{ + auto:{ + type:'VOID', + time: 100 + }, + saveCard: save_card_val, + threeDSecure: true, + description: "description", + statement_descriptor:"statement_descriptor", + reference:{ + transaction: '', + order: jQuery("#order_id").val() + }, + hashstring:jQuery("#hashstring").val(), + metadata:{}, + receipt:{ + email: false, + sms: true + }, + redirect: jQuery('#tap_end_url').val(), + post: jQuery('#post_url').val() + } + } + } + + if (tmode == 'charge') { + var transaction_mode = { + mode: 'charge', + charge:{ + saveCard: save_card_val, + threeDSecure: true, + description: "Test Description", + statement_descriptor: "Sample", + reference:{ + transaction: '', + order: jQuery("#order_id").val() + }, + hashstring:jQuery("#hashstring").val(), + metadata:{}, + receipt:{ + email: false, + sms: true + }, + redirect: jQuery('#tap_end_url').val(), + post: jQuery('#post_url').val() + } + } + } + + var config = { + gateway:{ + publicKey:active_pk, + language:Ui_language_val, + contactInfo:true, + supportedCurrencies:"all", + supportedPaymentMethods: "all", + saveCardOption:false, + customerCards: true, + notifications:'standard', + callback: (response) => { + console.log("response", response); + }, + labels:{ + cardNumber:"Card Number", + expirationDate:"MM/YY", + cvv:"CVV", + cardHolder:"Name on Card", + actionButton:"Pay" + }, + style: { + base: { + color: '#535353', + lineHeight: '18px', + fontFamily: 'sans-serif', + fontSmoothing: 'antialiased', + fontSize: '16px', + '::placeholder': { + color: 'rgba(0, 0, 0, 0.26)', + fontSize:'15px' + } + }, + invalid: { + color: 'red', + iconColor: '#fa755a ' + } + } + }, + customer:{ + id: '', + first_name: billing_first_name, + middle_name: "Middle Name", + last_name: billing_last_name, + email: billing_email, + phone: { + country_code: country_code, + number: billing_phone + } + }, + order:{ + amount: amount, + currency:currency, + items:items_values, + shipping:null, + taxes: null + }, + transaction:transaction_mode + } + + console.log(config); + if ( active_pk ) { + goSell.config(config); + } +}); + +var chg = jQuery("#chg").val(); +jQuery(function($){ + var checkout_form = jQuery( 'form.woocommerce-checkout' ); + checkout_form.on( 'checkout_place_order', chg); +}); \ No newline at end of file diff --git a/tap-payment.css b/tap-payment.css new file mode 100644 index 0000000..11d34af --- /dev/null +++ b/tap-payment.css @@ -0,0 +1,26 @@ +/*.gosell-gateway-list-container { + border:1px solid red !important; +} +#gosell-gateway-side-menu > .gosell-gateway-row >img{ + border:1px solid red !important; +} +.gosell-gateway-row > img { + border:1px solid red !important; + padding:0px !important; +} + +.gosell-gateway-row-icon > img { + padding: 0 !important; + margin-top: 3px !important; + margin-left:20px !important; + +}*/ +/**{ + box-sizing: unset !important; + -webkit-box-sizing: unset !important; + -moz-box-sizing: unset !important; + box-sizing: unset !important; +}*/ +.wc_payment_method>label:first-of-type img{ + float: revert; +} diff --git a/tap.js b/tap.js new file mode 100644 index 0000000..205d68e --- /dev/null +++ b/tap.js @@ -0,0 +1,103 @@ +function everyTime() { + if(document.getElementById('form-container')==null){ + + }else{ + var testmode = jQuery("#testmode").val(); + if(testmode == true) { + var active_pk = jQuery("#test_public_key").val(); + }else{ + var active_pk = jQuery("#publishable_key").val(); + } + var tap = Tapjsli(active_pk); + var elements = tap.elements({}); + var style = { + base: { + color: '#535353', + lineHeight: '18px', + fontFamily: 'sans-serif', + fontSmoothing: 'antialiased', + fontSize: '16px', + '::placeholder': { + color: 'rgba(0, 0, 0, 0.26)', + fontSize:'15px' + } + }, + invalid: { + color: 'red' + } + }; + + var labels = { + cardNumber:"Card Number", + expirationDate:"MM/YY", + cvv:"CVV", + cardHolder:"Card Holder Name" + }; + + var paymentOptions = { + currencyCode:'all', + labels : labels, + TextDirection:'ltr', + paymentAllowed: 'all', + } + console.log(paymentOptions); + var card = elements.create('card', {style: style},paymentOptions); + card.mount('#element-container'); + card.addEventListener('change', function(event) { + console.log(event) + if(event.code == '200' ){ + jQuery("#tap-btn").trigger("click"); + } + if(event.BIN){ + console.log(event.BIN) + } + if(event.loaded){ + console.log("UI loaded :"+event.loaded); + console.log("current currency is :"+card.getCurrency()) + } + var displayError = document.getElementById('error-handler'); + if (event.error) { + displayError.textContent = event.error.message; + } else { + displayError.textContent = ''; + } + }); + // Handle form submission + var form = document.getElementById('form-container'); + console.log(form); + if(form==null){ + return; + } + form.addEventListener('submit', function(event) { + event.preventDefault(); + + tap.createToken(card).then(function(result) { + if (result.error) { + // Inform the user if there was an error + var errorElement = document.getElementById('error-handler'); + errorElement.textContent = result.error.message; + } else { + // Send the token to your server + var errorElement = document.getElementById('success'); + errorElement.style.display = "block"; + var tokenElement = document.getElementById('token'); + + tokenElement.textContent = result.id; + var tokan = result.id; + var forms = jQuery("#wc-tap-cc-form"); + // token contains id, last4, and card type + var token = result.id; + + var parentOrderForm = jQuery('.woocommerce-checkout'); + var orderTokenInput = document.createElement("input"); + orderTokenInput.setAttribute("type", "hidden"); + orderTokenInput.setAttribute("name", "tap-woo-token"); + orderTokenInput.setAttribute("value", token); + parentOrderForm.append(orderTokenInput); + } + }); + }); + clearInterval(myInterval); + } +} +var myInterval = setInterval(everyTime, 1000); \ No newline at end of file diff --git a/tap.php b/tap.php new file mode 100644 index 0000000..15d6b3d --- /dev/null +++ b/tap.php @@ -0,0 +1,1227 @@ +id = 'tap'; // payment gateway plugin ID + $this->icon = ''; // URL of the icon that will be displayed on checkout page near your gateway name + $this->has_fields = false; // in case you need a custom credit card form + $this->method_title = 'Tap Gateway'; + $this->method_description = 'Get Paid via Tap Gateway'; // will be displayed on the options page + + $this->supports = array( + 'products', + 'refunds', + + ); + // Method with all the options fields + $this->init_form_fields(); + + // Load the settings. + $this->init_settings(); + + $this->icon = tap_imgdir . 'logo.png'; + $this->title = $this->get_option('title'); + $this->failer_page_id = $this->settings['failer_page_id']; + $this->success_page_id = $this->settings['success_page_id']; + $this->description = $this->get_option( 'description' ); + $this->enabled = $this->get_option('enabled'); + $this->testmode = 'yes' === $this->get_option('testmode'); + $this->api_key = $this->get_option('api_key'); + $this->test_secret_key = $this->get_option('test_secret_key'); + $this->test_public_key = $this->get_option('test_public_key'); + $this->live_secret_key = $this->get_option('live_secret_key'); + $this->live_public_key = $this->get_option('live_public_key'); + $this->payment_mode = $this->get_option('payment_mode'); + $this->type = 'type'; + $this->ui_mode = $this->get_option('ui_mode'); + $this->ui_language = $this->get_option('ui_language'); + $this->post_url = $this->get_option('post_url'); + $this->save_card = $this->get_option('save_card'); + + if($this->ui_mode == 'tokenization'){ + + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + add_action( 'woocommerce_order_status_completed', array($this, 'update_order_status'), 10, 1); + + // We need custom JavaScript to obtain a token + add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); + add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ), 11); + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + } + + add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ), 11); + add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); + + add_action( 'woocommerce_receipt_tap', array( $this, 'tap_checkout_receipt_page' ) ); + add_action( 'woocommerce_thankyou_tap', array( $this, 'tap_thank_you_page' ) ); + add_action( 'woocommerce_api_tap_webhook', array( $this, 'webhook' ) ); + + + + } + + public function webhook($order_id) { + $data = json_decode(file_get_contents("php://input"), true); + $headers = apache_request_headers(); + $header = getallheaders(); + $active_sk = ''; + if($this->testmode == '1') { + $active_sk = $this->test_secret_key; + }else { + $active_sk = $this->live_secret_key; + } + $orderid = $data['reference']['order']; + $status = $data['status']; + $charge_id = $data['id']; + $order = wc_get_order($orderid); + $order_currency = $order->get_currency(); + $order_amount = $order->get_total(); + + + if ($status !== 'CAPTURED' && $status !== 'AUTHORIZED') { + $order->update_status('cancelled'); + $order->add_order_note(sanitize_text_field('Tap payment failed..').("
").('ID').(':'). ($charge_id.("
").('Payment Type :') . ($data['source']['payment_method']).("
").('Payment Ref:'). ($data['reference']['payment']))); + + } + if (($order_amount == $data['amount']) && ($order_currency == $data['currency'])) { + if ($status == 'CAPTURED'){ + $order->update_status('processing'); + $order->add_order_note(sanitize_text_field('Tap payment successful..').("
").('ID').(':'). ($charge_id.("
").('Payment Type :') . ($data['source']['payment_method']).("
").('Payment Ref:'). ($data['reference']['payment']))); + $order->reduce_order_stock(); + update_option('webhook_debug', $_GET); + } + else if ($status == 'AUTHORIZED'){ + $order->update_status('pending'); + $order->add_order_note(sanitize_text_field('Tap payment successful..').("
").('ID').(':'). ($charge_id.("
").('Payment Type :') . ($data['source']['payment_method']).("
").('Payment Ref:'). ($data['reference']['payment']))); + } + } + else { + //if ($body['status'] == 'CAPTURED' && ($stat !== 'CANCELLED' || $stat !== 'CLOSED')) { + if ($data['status'] == 'CAPTURED') { + $refund_url = "https://api.tap.company/v2/refunds/"; + $refund_object["charge_id"] = $data['id']; + $refund_object["amount"] = $data['amount']; + $refund_object["currency"] = $data['currency']; + $refund_object["reason"] = "Order currency and response currency mismatch(fraudulent)"; + $refund_object["post_url"] = ""; + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => $refund_url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => json_encode($refund_object), + CURLOPT_HTTPHEADER => array( + "authorization: Bearer ".$active_sk, + "content-type: application/json" + ), + ) + ); + + $refund_response = curl_exec($curl); + $refund_response = json_decode($refund_response); + $order->update_status('cancelled'); + $order->add_order_note(sanitize_text_field('Tap payment decllined..').("
").('ID').(':'). ($charge_id.("
").('Payment Type :') . ($data['source']['payment_method']).("
").('Payment Ref:'). ($data['reference']['payment']). ('Refund ID' ) . $refund_response->id)); + } + if ($data['status'] == 'AUTHORIZED') { + $void_url = "https://api.tap.company/v2/authorize/".$data['id']."/void"; + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => $void_url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => "{}", + CURLOPT_HTTPHEADER => array( + "authorization: Bearer ".$active_sk, + "content-type: application/json" + ), + ) + ); + + $void_response = curl_exec($curl); + $void_response = json_decode($void_response); + $err = curl_error($curl); + curl_close($curl); + + $order->update_status('cancelled'); + $order->add_order_note(sanitize_text_field('Tap payment decllined..').("
").('ID').(':'). ($charge_id.("
").('Payment Type :') . ($data['source']['payment_method']).("
").('Payment Ref:'). ($data['reference']['payment']))); + } + } + + } + + + + public function tap_thank_you_page($order_id){ + global $woocommerce; + $active_sk = ''; + if($this->testmode == '1') { + $active_sk = $this->test_secret_key; + }else { + $active_sk = $this->live_secret_key; + } + if ($this->payment_mode == 'charge') { + $url = 'https://api.tap.company/v2/charges/'; + } + else { + $url = 'https://api.tap.company/v2/authorize/'; + } + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => $url.$_GET['tap_id'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "GET", + CURLOPT_HTTPHEADER => array( + "authorization: Bearer ".$active_sk, + "content-type: application/json" + ), + )); + $response = curl_exec($curl); + $response = json_decode($response); + + $order = wc_get_order( $order_id ); + $order_amount = $order->get_total(); + $order_currency = $order->get_currency(); + //$order_currency ='PKR'; + if ($response->status !== 'CAPTURED' && $charge_status !== 'AUTHORIZED') { + $order->update_status('cancelled'); + $order->add_order_note(sanitize_text_field('Tap payment failed').("
").('ID').(':'). ($_GET['tap_id'].("
").('Payment Type :') . ($response->source->payment_method).("
").('Payment Ref:'). ($response->reference->payment))); + $items = $order->get_items(); + foreach ( $items as $item ) { + $product_name = $item->get_name(); + $product_quantity = $item->get_quantity(); + $product_id = $item->get_product_id(); + $product_variation_id = $item->get_variation_id(); + $variation = new WC_Product_Variation($product_variation_id); + $variationName = implode(" / ", $variation->get_variation_attributes()); + $woocommerce->cart->add_to_cart( $product_id, $product_quantity, $product_variation_id , $variationName); + } + $failure_url = get_permalink($this->failer_page_id); + wp_redirect($failure_url); + wc_add_notice( __('Transaction Failed ', 'woothemes') . $error_message, 'error' ); + return; + exit; + } + if (empty($_GET['tap_id'])){ + $items = $order->get_items(); + foreach ( $items as $item ) { + $product_name = $item->get_name(); + $product_quantity = $item->get_quantity(); + $product_id = $item->get_product_id(); + $product_variation_id = $item->get_variation_id(); + $variation = new WC_Product_Variation($product_variation_id); + $variationName = implode(" / ", $variation->get_variation_attributes()); + $woocommerce->cart->add_to_cart( $product_id, $product_quantity, $product_variation_id , $variationName); + } + + $cart_url = $woocommerce->cart->get_cart_url(); + update_status('cancelled'); + wp_redirect($cart_url); + } + if (($order_amount == $response->amount) && ($order_currency == $response->currency)) { + + if (!empty($_GET['tap_id']) && $this->payment_mode == 'charge') { + if ($response->status == 'CAPTURED') { + $order->update_status('processing'); + $order->payment_complete($_GET['tap_id']); + update_post_meta( $order->id, '_transaction_id', $_GET['tap_id']); + $order->set_transaction_id( $_GET['tap_id'] ); + $order->add_order_note(sanitize_text_field('Tap payment successful').("
").('ID').(':'). ($_GET['tap_id'].("
").('Payment Type :') . ($response->source->payment_method).("
").('Payment Ref:'). ($response->reference->payment))); + $order->payment_complete($_GET['tap_id']); + $woocommerce->cart->empty_cart(); + if ( $this->success_page_id == "" || $this->success_page_id == 0 ) { + $redirect_url = $order->get_checkout_order_received_url(); + } else { + $redirect_url = get_permalink($this->success_page_id); + wp_redirect($redirect_url);exit; + } + } + } + + if (!empty($_GET['tap_id']) && $this->payment_mode == 'authorize') { + if ($response->status == 'AUTHORIZED') { + $order->update_status('pending'); + $order->add_order_note(sanitize_text_field('Tap payment successful').("
").('ID').(':'). ($_GET['tap_id'].("
").('Payment Type :') . ($response->source->payment_method).("
").('Payment Ref:'). ($response->reference->payment))); + $woocommerce->cart->empty_cart(); + if ( $this->success_page_id == "" || $this->success_page_id == 0 ) { + $redirect_url = $order->get_checkout_order_received_url(); + } else { + $redirect_url = get_permalink($this->success_page_id); + wp_redirect($redirect_url);exit; + } + }else { + $order->update_status('pending'); + if ( $this->failer_page_id == "" || $this->failer_page_id == 0 ) { + $failure_url = $this->get_return_url($order); + } else { + $failure_url = get_permalink($this->failer_page_id); + wp_redirect($failure_url); + wc_add_notice( __('Transaction Failed ', 'woothemes') . $error_message, 'error' ); + return; + exit; + } + } + } + } + else { + if ($response->status == 'CAPTURED') { + $refund_url = "https://api.tap.company/v2/refunds/"; + $refund_object["charge_id"] = $_REQUEST['tap_id']; + $refund_object["amount"] = $response->amount; + $refund_object["currency"] = $response->currency; + $refund_object["reason"] = "Order currency and response currency mismatch(fraudulent)"; + $refund_object["post_url"] = ""; + + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => $refund_url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => json_encode($refund_object), + CURLOPT_HTTPHEADER => array( + "authorization: Bearer ".$active_sk, + "content-type: application/json" + ), + ) + ); + + $refund_response = curl_exec($curl); + $refund_response = json_decode($refund_response); + $err = curl_error($curl); + curl_close($curl); + $order->update_status('cancelled'); + $order->add_order_note(sanitize_text_field('Tap declined payment error').("
").('ID').(':'). ($_GET['tap_id'].("
").('Payment Type :') . ($response->source->payment_method).("
").('Payment Ref:'). ($response->reference->payment). ('Refund ID').(':') . ($refund_response->id))); + if ( $this->failer_page_id == "" || $this->failer_page_id == 0 ) { + $failure_url = $this->get_return_url($order); + } else { + $failure_url = get_permalink($this->failer_page_id); + wp_redirect($failure_url); + wc_add_notice( __('Transaction Failed ', 'woothemes') . $error_message, 'error' ); + return; + } + } + + else if ($response->status == 'AUTHORIZED') + { + $void_url = "https://api.tap.company/v2/authorize/".$_REQUEST['tap_id']."/void"; + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => $void_url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => "{}", + CURLOPT_HTTPHEADER => array( + "authorization: Bearer ".$active_sk, + "content-type: application/json" + ), + ) + ); + + $void_response = curl_exec($curl); + $void_response = json_decode($void_response); + $err = curl_error($curl); + curl_close($curl); + $order->update_status('cancelled'); + $order->add_order_note(sanitize_text_field('Tap declined payment error').("
").('ID').(':'). ($_GET['tap_id'].("
").('Payment Type :') . ($response->source->payment_method).("
").('Payment Ref:'). ($response->reference->payment))); + if ( $this->failer_page_id == "" || $this->failer_page_id == 0 ) { + $failure_url = $this->get_return_url($order); + } else { + $failure_url = get_permalink($this->failer_page_id); + wp_redirect($failure_url); + wc_add_notice( __('Transaction Failed ', 'woothemes') . $error_message, 'error' ); + return; + } + } + } + } + + + public function tap_checkout_receipt_page($order_id) { + global $woocommerce; + + $items = WC()->cart->get_cart(); + $items = array_values(($items)); + $order = wc_get_order( $order_id ); + if($this->testmode == "testmode"){ + $active_pk = $this->test_public_key; + $active_sk = $this->test_secret_key; + }else{ + $active_pk = $this->live_public_key; + $active_sk = $this->live_secret_key; + } + $ref = ''; + if($order->currency=="KWD"){ + $Total_price = number_format((float)$order->total, 3, '.', ''); + }else{ + $Total_price = number_format((float)$order->total, 2, '.', ''); + } + $Hash = 'x_publickey'. $active_pk.'x_amount'.$Total_price.'x_currency'.$order->currency.'x_transaction'.$ref.'x_post'.get_site_url()."/wc-api/tap_webhook"; + $hashstring = hash_hmac('sha256', $Hash, $active_sk); + + $country_code = $this->getStorePhoneCountryCode($order->get_billing_country()); + + $current_user = wp_get_current_user(); + $first_name = $current_user->user_firstname; + $last_name = $current_user->user_lastname; + if(empty($first_name)){ + $first_name = $order->billing_first_name; + } + if(empty($last_name)){ + $last_name = $order->billing_last_name; + } + + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + foreach($items as $key=>$item) { + $price = $item['data']->price; + if($item['data']->sale_price){ + $price = $item['data']->sale_price; + } + echo ''; + } + if ( $this->ui_mode == 'popup') { + ?> + + '; + } + } + + + public function init_form_fields(){ + + $this->form_fields = array( + 'enabled' => array( + 'title' => 'Enable/Disable', + 'label' => 'Enable Tap Gateway', + 'type' => 'checkbox', + 'description' => '', + 'default' => 'no' + ), + 'title' => array( + 'title' => 'Title', + 'type' => 'text', + 'description' => 'This controls the title which the user sees during checkout.', + 'default' => 'Credit Card', + 'desc_tip' => true, + ), + 'description' => array( + 'title' => 'Description', + 'type' => 'textarea', + 'description' => 'This controls the description which the user sees during checkout.', + 'default' => 'Pay with your credit card via Tap payment gateway. On clicking Place order payment will be processed.', + ), + 'testmode' => array( + 'title' => 'Test mode', + 'label' => 'Enable Test Mode', + 'type' => 'checkbox', + 'description' => 'Place the payment gateway in test mode using test API keys.', + 'default' => 'yes', + 'desc_tip' => true, + ), + 'test_secret_key' => array( + 'title' => 'Test Secret Key', + 'type' => 'text' + ), + 'test_public_key' => array( + 'title' => 'Test Public Key', + 'type' => 'text' + ), + 'live_public_key' => array( + 'title' => 'Live Public Key', + 'type' => 'text' + ), + 'live_secret_key' => array( + 'title' => 'Live Secret Key', + 'type' => 'text' + ), + 'payment_mode' => array( + 'title' => 'Payment Mode', + 'type' => 'select', + 'class' => 'wc-enhanced-select', + 'default' => '', + 'desc_tip' => true, + 'options' => array( + 'charge' => 'Charge', + 'authorize' => 'Authorize', + ) + ), + 'ui_mode' => array( + 'title' => 'Ui Mode', + 'type' => 'select', + 'class' => 'wc-enhanced-select', + 'default' => '', + 'desc_tip' => true, + 'options' => array( + 'redirect' => 'redirect', + 'popup' => 'popup', + 'tokenization' => 'Tokanization', + ) + ), + 'ui_language' => array( + 'title' => 'Ui Language', + 'type' => 'select', + 'class' => 'wc-enhanced-select', + 'default' => '', + 'desc_tip' => true, + 'options' => array( + 'english' => 'English', + 'arabic' => 'Arabic', + ) + ), + 'failer_page_id' => array( + 'title' => __('Return to failure Page'), + 'type' => 'select', + 'options' => $this->tap_get_pages('Select Page'), + 'description' => __('URL of failure page', 'kdc'), + 'desc_tip' => true + ), + 'success_page_id' => array( + 'title' => __('Return to success Page'), + 'type' => 'select', + 'options' => $this->tap_get_pages('Select Page'), + 'description' => __('URL of success page', 'kdc'), + 'desc_tip' => true + ), + 'post_url' => array( + 'title' => 'Post URL', + 'type' => 'text' + ), + 'save_card' => array( + 'title' => 'Save Cards', + 'label' => 'Check if you want to save card data', + 'type' => 'checkbox', + 'description' => '', + 'default' => 'no' + ) + ); + } + + public function admin_scripts(){ + wp_enqueue_script('tap2', plugin_dir_url(__FILE__) . '/tap2.js'); + } + + public function payment_scripts() { + if ($this->ui_mode == 'tokenization'){ + echo ''; + wp_register_style( 'tap_payment', plugins_url('tap-payment.css', __FILE__)); + wp_enqueue_script( 'tap_js', 'https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.3.4/bluebird.min.js' ); + wp_enqueue_script( 'tap_js2', 'https://secure.gosell.io/js/sdk/tapjsli.js' ); + wp_register_script( 'woocommerce_tap', plugins_url( 'tap.js', __FILE__ ), array( 'jquery', 'tap_js' ) ); + wp_localize_script( 'woocommerce_tap', 'tap_params', array( + 'publishableKey' => $this->live_public_key + )); + wp_enqueue_style( 'tap-payment', plugins_url( 'tap-payment.css', __FILE__ ) ); + wp_enqueue_script( 'woocommerce_tap' ); + + } + + if ($this->ui_mode == 'popup' || $this->ui_mode == 'redirect' ){ + wp_register_style( 'tap_payment', plugins_url('tap-payment.css', __FILE__)); + wp_enqueue_style('tap_payment'); + wp_register_style( 'tap_style', '//goSellJSLib.b-cdn.net/v1.6.1/css/gosell.css' ); + wp_register_style( 'tap_icon', '//goSellJSLib.b-cdn.net/v1.6.1/imgs/tap-favicon.ico' ); + wp_enqueue_style('tap_style'); + wp_enqueue_style('tap_icon'); + wp_enqueue_script( 'tap_js', '//goSellJSLib.b-cdn.net/v1.6.1/js/gosell.js', array('jquery') ); + wp_register_script( 'woocommerce_tap', plugins_url( 'taap.js', __FILE__ ), 'gosell'); + wp_enqueue_style( 'tap-payment', plugins_url( 'tap-payment.css', __FILE__ ) ); + wp_enqueue_script( 'woocommerce_tap' ); + } + } + + public function getStorePhoneCountryCode($country_code) + { + $countrycode = array( + 'AD'=>'376', + 'AE'=>'971', + 'AF'=>'93', + 'AG'=>'1268', + 'AI'=>'1264', + 'AL'=>'355', + 'AM'=>'374', + 'AN'=>'599', + 'AO'=>'244', + 'AQ'=>'672', + 'AR'=>'54', + 'AS'=>'1684', + 'AT'=>'43', + 'AU'=>'61', + 'AW'=>'297', + 'AZ'=>'994', + 'BA'=>'387', + 'BB'=>'1246', + 'BD'=>'880', + 'BE'=>'32', + 'BF'=>'226', + 'BG'=>'359', + 'BH'=>'973', + 'BI'=>'257', + 'BJ'=>'229', + 'BL'=>'590', + 'BM'=>'1441', + 'BN'=>'673', + 'BO'=>'591', + 'BR'=>'55', + 'BS'=>'1242', + 'BT'=>'975', + 'BW'=>'267', + 'BY'=>'375', + 'BZ'=>'501', + 'CA'=>'1', + 'CC'=>'61', + 'CD'=>'243', + 'CF'=>'236', + 'CG'=>'242', + 'CH'=>'41', + 'CI'=>'225', + 'CK'=>'682', + 'CL'=>'56', + 'CM'=>'237', + 'CN'=>'86', + 'CO'=>'57', + 'CR'=>'506', + 'CU'=>'53', + 'CV'=>'238', + 'CX'=>'61', + 'CY'=>'357', + 'CZ'=>'420', + 'DE'=>'49', + 'DJ'=>'253', + 'DK'=>'45', + 'DM'=>'1767', + 'DO'=>'1809', + 'DZ'=>'213', + 'EC'=>'593', + 'EE'=>'372', + 'EG'=>'20', + 'ER'=>'291', + 'ES'=>'34', + 'ET'=>'251', + 'FI'=>'358', + 'FJ'=>'679', + 'FK'=>'500', + 'FM'=>'691', + 'FO'=>'298', + 'FR'=>'33', + 'GA'=>'241', + 'GB'=>'44', + 'GD'=>'1473', + 'GE'=>'995', + 'GH'=>'233', + 'GI'=>'350', + 'GL'=>'299', + 'GM'=>'220', + 'GN'=>'224', + 'GQ'=>'240', + 'GR'=>'30', + 'GT'=>'502', + 'GU'=>'1671', + 'GW'=>'245', + 'GY'=>'592', + 'HK'=>'852', + 'HN'=>'504', + 'HR'=>'385', + 'HT'=>'509', + 'HU'=>'36', + 'ID'=>'62', + 'IE'=>'353', + 'IL'=>'972', + 'IM'=>'44', + 'IN'=>'91', + 'IQ'=>'964', + 'IR'=>'98', + 'IS'=>'354', + 'IT'=>'39', + 'JM'=>'1876', + 'JO'=>'962', + 'JP'=>'81', + 'KE'=>'254', + 'KG'=>'996', + 'KH'=>'855', + 'KI'=>'686', + 'KM'=>'269', + 'KN'=>'1869', + 'KP'=>'850', + 'KR'=>'82', + 'KW'=>'965', + 'KY'=>'1345', + 'KZ'=>'7', + 'LA'=>'856', + 'LB'=>'961', + 'LC'=>'1758', + 'LI'=>'423', + 'LK'=>'94', + 'LR'=>'231', + 'LS'=>'266', + 'LT'=>'370', + 'LU'=>'352', + 'LV'=>'371', + 'LY'=>'218', + 'MA'=>'212', + 'MC'=>'377', + 'MD'=>'373', + 'ME'=>'382', + 'MF'=>'1599', + 'MG'=>'261', + 'MH'=>'692', + 'MK'=>'389', + 'ML'=>'223', + 'MM'=>'95', + 'MN'=>'976', + 'MO'=>'853', + 'MP'=>'1670', + 'MR'=>'222', + 'MS'=>'1664', + 'MT'=>'356', + 'MU'=>'230', + 'MV'=>'960', + 'MW'=>'265', + 'MX'=>'52', + 'MY'=>'60', + 'MZ'=>'258', + 'NA'=>'264', + 'NC'=>'687', + 'NE'=>'227', + 'NG'=>'234', + 'NI'=>'505', + 'NL'=>'31', + 'NO'=>'47', + 'NP'=>'977', + 'NR'=>'674', + 'NU'=>'683', + 'NZ'=>'64', + 'OM'=>'968', + 'PA'=>'507', + 'PE'=>'51', + 'PF'=>'689', + 'PG'=>'675', + 'PH'=>'63', + 'PK'=>'92', + 'PL'=>'48', + 'PM'=>'508', + 'PN'=>'870', + 'PR'=>'1', + 'PT'=>'351', + 'PW'=>'680', + 'PY'=>'595', + 'QA'=>'974', + 'RO'=>'40', + 'RS'=>'381', + 'RU'=>'7', + 'RW'=>'250', + 'SA'=>'966', + 'SB'=>'677', + 'SC'=>'248', + 'SD'=>'249', + 'SE'=>'46', + 'SG'=>'65', + 'SH'=>'290', + 'SI'=>'386', + 'SK'=>'421', + 'SL'=>'232', + 'SM'=>'378', + 'SN'=>'221', + 'SO'=>'252', + 'SR'=>'597', + 'ST'=>'239', + 'SV'=>'503', + 'SY'=>'963', + 'SZ'=>'268', + 'TC'=>'1649', + 'TD'=>'235', + 'TG'=>'228', + 'TH'=>'66', + 'TJ'=>'992', + 'TK'=>'690', + 'TL'=>'670', + 'TM'=>'993', + 'TN'=>'216', + 'TO'=>'676', + 'TR'=>'90', + 'TT'=>'1868', + 'TV'=>'688', + 'TW'=>'886', + 'TZ'=>'255', + 'UA'=>'380', + 'UG'=>'256', + 'US'=>'1', + 'UY'=>'598', + 'UZ'=>'998', + 'VA'=>'39', + 'VC'=>'1784', + 'VE'=>'58', + 'VG'=>'1284', + 'VI'=>'1340', + 'VN'=>'84', + 'VU'=>'678', + 'WF'=>'681', + 'WS'=>'685', + 'XK'=>'381', + 'YE'=>'967', + 'YT'=>'262', + 'ZA'=>'27', + 'ZM'=>'260', + 'ZW'=>'263' + ); + return $countrycode[$country_code]; + } + + public function payment_fields() { + + if ($this->ui_mode == 'tokenization'){ + + echo '
+ +
+ +
+ +
+ + + '.' + + + + +
'; + } + + if ($this->ui_mode == 'popup' || $this->ui_mode == 'redirect' ){ + + global $woocommerce; + $customer_user_id = get_current_user_id(); + $currency = get_woocommerce_currency(); + $amount = $woocommerce->cart->total; + $mode = $this->payment_mode; + if ( $this->description ) { + if ( $this->testmode ) { + $this->description .= ' TEST MODE ENABLED. In test mode, you can use the card numbers mentioned in documentation'; + $this->description = trim( $this->description ); + } + echo wpautop( wp_kses_post( $this->description ) ); + } + echo '
'; + + do_action( 'woocommerce_credit_card_form_start', $this->id ); + ?> +
+ id ); + echo '
'; + } + + } + + public function process_payment($order_id) { + + $order = new WC_Order( $order_id ); + + if ($this->ui_mode == 'popup'){ + global $woocommerce; + + return array( + 'result' => 'success', + 'redirect' => $order->get_checkout_payment_url( true ) + ); + } + + if ($this->ui_mode == 'redirect') { + + $currencyCode = $order->get_currency(); + $orderid = $order->get_id(); + $order_items = $order->get_items(); + $table_prefix = $wpdb->prefix; + if ($this->payment_mode == 'authorize') { + $charge_url = 'https://api.tap.company/v2/authorize'; + } + else { + $charge_url = 'https://api.tap.company/v2/charges'; + } + $first_name = isset($_POST['billing_first_name']) ? $_POST['billing_first_name'] : $order->get_billing_first_name(); + $last_name = isset($_POST['billing_last_name']) ? $_POST['billing_last_name'] : $order->get_billing_last_name(); + $country = isset($_POST['billing_country']) ? $_POST['billing_country'] : $order->get_billing_country(); + $city = isset($_POST['billing_city']) ? $_POST['billing_city'] : $order->get_billing_city(); + $billing_address = isset($_POST['billing_address_1']) ? $_POST['billing_address_1'] : $order->get_billing_address_1(); + $country_code = $this->getStorePhoneCountryCode($country); + $return_url = $order->get_checkout_order_received_url(); + $billing_email = isset($_POST['billing_email']) ? $_POST['billing_email'] : $order->get_billing_email(); + $biliing_fone = isset($_POST['billing_phone']) ? $_POST['billing_phone'] : $order->get_billing_phone(); + $avenue = isset($_POST['billing_address_2']) ? $_POST['billing_address_2'] : $order->get_billing_address_2(); + $order_amount = $order->get_total(); + $post_url = get_site_url()."/wc-api/tap_webhook"; + if($this->testmode == "testmode"){ + $active_pk = $this->test_public_key; + $active_sk = $this->test_secret_key; + }else{ + $active_pk = $this->live_public_key; + $active_sk = $this->live_secret_key; + } + $ref = ''; + + if($currencyCode=="KWD" || $currencyCode == "BHD" || $currencyCode == "OMR"){ + $order_amount = number_format((float)$order->get_total(), 3, '.', ''); + }else{ + $order_amount = number_format((float)$order->get_total(), 2, '.', ''); + } + + $Hash = 'x_publickey'. $active_pk.'x_amount'.$order_amount.'x_currency'.$currencyCode.'x_transaction'.$ref.'x_post'.get_site_url()."/wc-api/tap_webhook"; + $hashstring = hash_hmac('sha256', $Hash, $active_sk); + + $source_id = 'src_all'; + $trans_object["amount"] = $order_amount; + $trans_object["currency"] = $currencyCode; + $trans_object["threeDsecure"] = true; + $trans_object["save_card"] = false; + $trans_object["description"] = $orderid; + $trans_object["statement_descriptor"] = 'Sample'; + $trans_object["metadata"]["udf1"] = 'test'; + $trans_object["metadata"]["udf2"] = 'test'; + $trans_object["reference"]["transaction"] = 'txn_0001'; + $trans_object["hashstring"] = $hashstring; + $trans_object["reference"]["order"] = $orderid; + $trans_object["receipt"]["email"] = false; + $trans_object["receipt"]["sms"] = true; + $trans_object["customer"]["first_name"] = $first_name; + $trans_object["customer"]["last_name"] = $last_name; + $trans_object["customer"]["email"] = $billing_email; + $trans_object["customer"]["phone"]["country_code"] = $country_code; + $trans_object["customer"]["phone"]["number"] = $biliing_fone; + $trans_object["source"]["id"] = $source_id; + $trans_object["post"]["url"] = $post_url; + $trans_object["redirect"]["url"] = $return_url; + $frequest = json_encode($trans_object, JSON_UNESCAPED_UNICODE); + $frequest = stripslashes($frequest); + + if($this->testmode == "testmode"){ + $active_pk = $this->test_public_key; + $active_sk = $this->test_secret_key; + }else{ + $active_pk = $this->live_public_key; + $active_sk = $this->live_secret_key; + } + + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => $charge_url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => $frequest, + CURLOPT_HTTPHEADER => array( + "authorization: Bearer ".$active_sk, + "content-type: application/json" + ), + )); + + $response = curl_exec($curl); + $err = curl_error($curl); + $obj = json_decode($response); + $charge_id = $obj->id; + $redirct_Url = $obj->transaction->url; + + return array( + 'result' => 'success', + 'redirect' => $redirct_Url + ); + } + + if ($this->ui_mode == 'tokenization'){ + + global $woocommerce,$wpdb; + + $token = new WC_Payment_Token_CC(); + $wooToken = $_POST['tap-woo-token']; + $order = wc_get_order($order_id); + $currencyCode = $order->get_currency(); + $orderid = $order->get_id(); + $order_amount = $order->get_total(); + $table_prefix = $wpdb->prefix; + + if($this->testmode == "testmode"){ + $active_pk = $this->test_public_key; + $active_sk = $this->test_secret_key; + }else{ + $active_pk = $this->live_public_key; + $active_sk = $this->live_secret_key; + } + + $ref = ''; + if($currencyCode=="KWD" || $currencyCode=="BHD" || $currencyCode=="OMR"){ + $order_amount = number_format((float)$order->get_total(), 3, '.', ''); + }else{ + $order_amount = number_format((float)$order->get_total(), 2, '.', ''); + } + + $Hash = 'x_publickey'. $active_pk.'x_amount'.$order_amount.'x_currency'.$currencyCode.'x_transaction'.$ref.'x_post'.get_site_url()."/wc-api/tap_webhook"; + $hashstring = hash_hmac('sha256', $Hash, $active_sk); + + $charge_url = 'https://api.tap.company/v2/charges'; + $first_name = $_POST['billing_first_name']; + $last_name = $_POST['billing_last_name']; + $country = $_POST['billing_country']; + $country_code = $this->getStorePhoneCountryCode($country); + $city = $_POST['billing_city']; + $billing_address = $_POST['billing_address_1']; + $return_url = $order->get_checkout_order_received_url(); + $billing_email = $_POST['billing_email']; + $biliing_fone = $_POST['billing_phone']; + $avenue = $_POST['billing_address_2']; + $order_amount = $order->get_total(); + + if( $this->save_card == 'no') { + $save_card_val = false; + }else { + $save_card_val = true; + } + + $trans_object["amount"] = $order_amount; + $trans_object["currency"] = $currencyCode; + $trans_object["threeDsecure"] = true; + $trans_object["save_card"] = $save_card_val; + $trans_object["description"] = 'Test Description'; + $trans_object["statement_descriptor"] = 'Sample'; + $trans_object["metadata"]["udf1"] = 'test'; + $trans_object["metadata"]["udf2"] = 'test'; + $trans_object["reference"]["transaction"] = 'txn_0001'; + $trans_object["reference"]["order"] = $orderid; + $trans_object["receipt"]["email"] = false; + $trans_object["receipt"]["sms"] = true; + $trans_object["customer"]["first_name"] = $first_name; + $trans_object["customer"]["last_name"] = $last_name; + $trans_object["customer"]["email"] = $billing_email; + $trans_object["customer"]["phone"]["country_code"] = $country_code; + $trans_object["customer"]["phone"]["number"] = $biliing_fone; + $trans_object["source"]["id"] = $wooToken; + $trans_object["post"]["url"] = get_site_url()."/wc-api/tap_webhook"; + $trans_object["redirect"]["url"] = $return_url; + $frequest = json_encode($trans_object, JSON_UNESCAPED_UNICODE); + $frequest = stripslashes($frequest); + + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => $charge_url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => $frequest, + CURLOPT_HTTPHEADER => array( + "authorization: Bearer ".$active_sk, + "content-type: application/json" + ), + )); + + $response = curl_exec($curl); + $err = curl_error($curl); + $obj = json_decode($response); + + if ($obj->transaction->url == '') { + if ( $this->failer_page_id == "" || $this->failer_page_id == 0 ) { + $failure_url = $this->get_return_url($order); + } else { + $failure_url = get_permalink($this->failer_page_id); + } + return array( + 'result' => 'failure', + 'redirect' => $failure_url + ); + } + + return array( + 'result' => 'success', + 'redirect' => $obj->transaction->url + ); + } + } + + public function tap_get_pages($title = false, $indent = true) { + $wp_pages = get_pages('sort_column=menu_order'); + $page_list = array(); + if ($title) $page_list[] = $title; + foreach ($wp_pages as $page) { + $prefix = ''; + //show indented child pages? + if ($indent) { + $has_parent = $page->post_parent; + while($has_parent) { + $prefix .= ' - '; + $next_page = get_post($has_parent); + $has_parent = $next_page->post_parent; + } + } + //add to page list array array + $page_list[$page->ID] = $prefix . $page->post_title; + } + return $page_list; + } + + public function process_refund($order_id, $amount = null, $reason = ''){ + global $post, $woocommerce; + + $order = new WC_Order($order_id); + $transID = get_post_meta( $order->id, '_transaction_id'); + $currency = $order->currency; + $refund_url = 'https://api.tap.company/v2/refunds'; + $refund_request['charge_id'] = $transID; + $refund_request['amount'] = $amount; + $refund_request['currency'] = $currency; + $refund_request['description'] = "Description"; + $refund_request['reason'] = $reason; + $refund_request['reference']['merchant'] = "txn_0001"; + $refund_request['metadata']['udf1']= "test1"; + $refund_request['metadata']['udf2']= "test2"; + $refund_request['post']['url'] = "http://your_url.com/post"; + $json_request = json_encode($refund_request); + $json_request = str_replace( '\/', '/', $json_request ); + $json_request = str_replace(array('[',']'),'',$json_request); + + $active_sk = ''; + if($this->testmode == '1') { + $active_sk = $this->test_secret_key; + }else { + $active_sk = $this->live_secret_key; + } + + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => "https://api.tap.company/v2/refunds", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS =>$json_request, + CURLOPT_HTTPHEADER => array( + "authorization: Bearer ".$active_sk, + "content-type: application/json" + ), + )); + + $response = curl_exec($curl);; + $response = json_decode($response); + if ($response->id) { + if ( $response->status == 'PENDING') { + $order->add_order_note(sanitize_text_field('Tap Refund successful').("
").'Refund ID'.("
"). $response->id); + return true; + } + }else { + return false; + } + } + } +} + + +//Support for the Checkout Block +add_action('woocommerce_blocks_loaded', 'woocommerce_gateway_tap_woocommerce_block_support'); + +function woocommerce_gateway_tap_woocommerce_block_support() { + if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) { + require_once dirname( __FILE__ ) . '/class-wc-tap-blocks-support.php'; + add_action( + 'woocommerce_blocks_payment_method_type_registration', + function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { + + $container = Automattic\WooCommerce\Blocks\Package::container(); + // registers as shared instance. + $container->register( + WC_Tap_Blocks_Support::class, + function(Automattic\WooCommerce\Blocks\Registry\Container $container) { + $asset_api = $container->get( Automattic\WooCommerce\Blocks\Assets\Api::class ); + return new WC_Tap_Blocks_Support($asset_api); + } + ); + $payment_method_registry->register( + $container->get( WC_Tap_Blocks_Support::class ) + ); + }, + ); + } +} diff --git a/tap2.js b/tap2.js new file mode 100644 index 0000000..a2ca07f --- /dev/null +++ b/tap2.js @@ -0,0 +1,20 @@ +jQuery( document ).ready(function() { + jQuery('#woocommerce_tap_test_publishable_key').show(); + jQuery('label[for=woocommerce_tap_test_publishable_key], input#a').show(); + jQuery('label[for=woocommerce_tap_test_private_key], input#a').show(); + jQuery('#woocommerce_tap_test_private_key ').show(); + jQuery('#woocommerce_tap_publishable_key').hide(); + jQuery('#woocommerce_tap_private_key').hide(); + jQuery('label[for=woocommerce_tap_publishable_key], input#a').hide(); + jQuery('label[for=woocommerce_tap_private_key], input#a').hide(); + jQuery('#woocommerce_tap_testmode').click(function(){ + jQuery('#woocommerce_tap_test_publishable_key').toggle(); + jQuery('#woocommerce_tap_test_private_key').toggle(); + jQuery('label[for=woocommerce_tap_test_publishable_key], input#a').toggle(); + jQuery('label[for=woocommerce_tap_test_private_key], input#a').toggle(); + jQuery('#woocommerce_tap_publishable_key').toggle(); + jQuery('#woocommerce_tap_private_key').toggle(); + jQuery('label[for=woocommerce_tap_publishable_key], input#a').toggle(); + jQuery('label[for=woocommerce_tap_private_key], input#a').toggle(); + }); +}); diff --git a/wc-payment-method-tap.js b/wc-payment-method-tap.js new file mode 100644 index 0000000..f82b230 --- /dev/null +++ b/wc-payment-method-tap.js @@ -0,0 +1,87 @@ +! function(e) { + + var t = {}; + + function n(o) { + if (t[o]) return t[o].exports; + var r = t[o] = { + i: o, + l: !1, + exports: {} + }; + return e[o].call(r.exports, r, r.exports, n), r.l = !0, r.exports + } + n.m = e, n.c = t, n.d = function(e, t, o) { + n.o(e, t) || Object.defineProperty(e, t, { + enumerable: !0, + get: o + }) + }, n.r = function(e) { + "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { + value: "Module" + }), Object.defineProperty(e, "__esModule", { + value: !0 + }) + }, n.t = function(e, t) { + if (1 & t && (e = n(e)), 8 & t) return e; + if (4 & t && "object" == typeof e && e && e.__esModule) return e; + var o = Object.create(null); + if (n.r(o), Object.defineProperty(o, "default", { + enumerable: !0, + value: e + }), 2 & t && "string" != typeof e) + for (var r in e) n.d(o, r, function(t) { + return e[t] + }.bind(null, r)); + return o + }, n.n = function(e) { + var t = e && e.__esModule ? function() { + return e.default + } : function() { + return e + }; + return n.d(t, "a", t), t + }, n.o = function(e, t) { + return Object.prototype.hasOwnProperty.call(e, t) + }, n.p = "", n(n.s = 6) +}([function(e, t) { + e.exports = window.wp.element +}, function(e, t) { + e.exports = window.wp.htmlEntities +}, function(e, t) { + e.exports = window.wp.i18n +}, function(e, t) { + e.exports = window.wc.wcSettings +}, function(e, t) { + e.exports = window.wc.wcBlocksRegistry +}, , function(e, t, n) { + "use strict"; + n.r(t); + var o, r = n(0), + c = n(4), + i = n(2), + u = n(3), + a = n(1); + var logo_src = u.WC_ASSET_URL; + logo_src = logo_src.replace('woocommerce/assets/', ''); + + const l = Object(u.getSetting)("tap_data", {}), + p = () => Object(a.decodeEntities)(l.description || ""), + s = { + name: "tap", + label: Object(r.createElement)("img", { + src: logo_src + "/tap-all-in-one/assets/img/logo.png", + alt: Object(a.decodeEntities)(l.title || Object(i.__)("Tap", "woocommerce")) + }), + placeOrderButtonLabel: Object(i.__)("Proceed to Tap", "woocommerce"), + content: Object(r.createElement)(p, null), + edit: Object(r.createElement)(p, null), + canMakePayment: () => !0, + ariaLabel: Object(a.decodeEntities)(l.title || Object(i.__)("Payment via Tap", "woocommerce")), + supports: { + features: null !== (o = l.supports) && void 0 !== o ? o : [] + } + }; + + Object(c.registerPaymentMethod)(s) +}]); \ No newline at end of file