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 '