'Form ID/Name', '_payer_email' => 'Payer Email Address', '_transaction_id' => 'Transaction ID', '_invoice_no' => 'Invoice ID', '_amount' => 'Amount', '_quantity' => 'Quantity', '_total' => 'Total', '_submit_time' => 'Submit Time', '_request_Ip' => 'Request IP', '_currency' => 'Currency code', '_form_data' => 'Form data', '_transaction_response' => 'Transaction response', '_transaction_status' => 'Transaction status', ); function __construct() { add_action( 'init', array( $this, 'action__init' ) ); add_action( 'wpcf7_before_send_mail', array( $this, 'action__wpcf7_before_send_mail' ), 20, 3 ); add_action( CF7WPA_PREFIX . '/worldpay/save/data', array( $this, 'action__cf7wpa_worldpay_save_data' ), 10, 3 ); add_shortcode( 'worldpay-transaction-details', array( $this, 'shortcode__worldpay_pro_success' ) ); add_action( 'wpcf7_init', array( $this, 'action__wpcf7_verify_version' ), 10, 0 ); //add_filter( 'wpcf7_ajax_json_echo', array( $this, 'filter__wpcf7_ajax_json_echo' ), 20, 2 ); } /* ### ###### ######## #### ####### ## ## ###### ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## #### ## ## ## ## ## ## ## ## ## ## ## ## ###### ######### ## ## ## ## ## ## #### ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ###### ## #### ####### ## ## ###### */ /** * Action: init * * - Fire the email when return back from the worldpay. * * @method action__init * */ function action__init() { if ( !isset( $_SESSION ) || session_status() == PHP_SESSION_NONE ) { session_start(); } if ( isset( $_REQUEST['transId' ] ) ) { $payment_details['TransID'] = addslashes( $_REQUEST["transId"] ); $postDataSaveInTransiest = get_transient( 'form_data_'.$_REQUEST['cartId'] ); $payment_details = $_REQUEST; do_action( CF7WPA_PREFIX . '/worldpay/save/data', $postDataSaveInTransiest, $token = $_REQUEST['cartId' ], $payment_details ); $payment_details_json = json_encode($payment_details); if ( (isset($_REQUEST["transId"]) && $_REQUEST["transStatus"]=='Y') ) { $success_url_field = get_post_meta( $_REQUEST["MC_order"], CF7WPA_META_PREFIX . 'success_returnurl', true); if( $success_url_field != 'Select page' ){ $url = get_permalink( $success_url_field ); } else { $succesPage = get_page_by_path( 'worldpay-thank-you' ); if($succesPage){ $url = get_permalink( $succesPage ); } else { $url = get_home_url(); } } echo ""; } else { $cancel_url_field = get_post_meta( $_REQUEST["MC_order"], CF7WPA_META_PREFIX . 'cancel_returnurl', true); if( $cancel_url_field != 'Select page'){ $url = get_permalink( $cancel_url_field ); } else { $url = get_home_url(); } echo ""; } } if(isset($_SESSION[CF7WPA_META_PREFIX . 'form_transiest_uniq_id'])){ $transientId = $_SESSION[CF7WPA_META_PREFIX . 'form_transiest_uniq_id']; } if ( empty( $transientId ) ) return '
' . __( 'Something goes wrong! Please try again.', 'contact-form-7-worldpay-addon' ) . '
'; if ( true == ( $valuePayment = get_transient( "payment_response_".$transientId ) ) ) { $postSaveInTransiestPayment = get_transient( "payment_response_".$transientId ); } if ( empty( $postSaveInTransiestPayment ) ) return '' . __( 'Something goes wrong! Please try again.', 'contact-form-7-worldpay-addon' ) . '
'; if ( true == ( $valueFormData = get_transient( "form_data_".$transientId ) ) ) { $postSaveInTransiestFormData = get_transient( "form_data_".$transientId ); } /** * Fire email after failed/cancel payment from worldpay */ if ( !empty( $postSaveInTransiestFormData ) && !empty( $postSaveInTransiestPayment ) && isset( $_SESSION[ CF7WPA_META_PREFIX . 'form_submitted_flag' ] ) && $postSaveInTransiestPayment != null && !isset($postSaveInTransiestPayment["transId"]) && $postSaveInTransiestPayment["transStatus"] !='Y' ) { $from_data = $postSaveInTransiestFormData ; $form_ID = $from_data->get_contact_form()->id(); add_filter( 'wpcf7_mail_components', array( $this, 'filter__wpcf7_mail_components' ), 888, 3 ); $this->cf7wpa_mail( $from_data, $from_data->get_posted_data() , $postSaveInTransiestPayment ); remove_filter( 'wpcf7_mail_components', array( $this, 'filter__wpcf7_mail_components' ), 888, 3 ); if ( isset( $_SESSION[ CF7WPA_META_PREFIX . 'form_submitted_flag' ] ) ) { unset( $_SESSION[ CF7WPA_META_PREFIX . 'form_submitted_flag' ] ); } } /** * Fire email after success payment from Worldpay */ if ( !empty( $postSaveInTransiestFormData ) && !empty( $postSaveInTransiestPayment ) && isset( $_SESSION[ CF7WPA_META_PREFIX . 'form_submitted_flag' ] ) && $postSaveInTransiestPayment != null && isset($postSaveInTransiestPayment["transId"]) && $postSaveInTransiestPayment["transStatus"]=='Y' ) { $from_data = $postSaveInTransiestFormData ; $form_ID = $from_data->get_contact_form()->id(); add_filter( 'wpcf7_mail_components', array( $this, 'filter__wpcf7_mail_components' ), 888, 3 ); $this->cf7wpa_mail( $from_data, $from_data->get_posted_data() , $postSaveInTransiestPayment ); remove_filter( 'wpcf7_mail_components', array( $this, 'filter__wpcf7_mail_components' ), 888, 3 ); if ( isset( $_SESSION[ CF7WPA_META_PREFIX . 'form_submitted_flag' ] ) ) { unset( $_SESSION[ CF7WPA_META_PREFIX . 'form_submitted_flag' ] ); } } } /** * Worldpay Verify CF7 dependencies. * * @method action__wpcf7_verify_version * */ function action__wpcf7_verify_version(){ $cf7_verify = $this->wpcf7_version(); if ( version_compare($cf7_verify, '5.2') >= 0 ) { add_filter( 'wpcf7_feedback_response', array( $this, 'filter__wpcf7_ajax_json_echo' ), 20, 2 ); } else{ add_filter( 'wpcf7_ajax_json_echo', array( $this, 'filter__wpcf7_ajax_json_echo' ), 20, 2 ); } } /** * Action: CF7 before send email * * @method action__wpcf7_before_send_mail * * @param object $contact_form WPCF7_ContactForm::get_instance() * */ function action__wpcf7_before_send_mail( $contact_form ) { $submission = WPCF7_Submission::get_instance(); // CF7 Submission Instance $form_ID = $contact_form->id(); $form_instance = WPCF7_ContactForm::get_instance($form_ID); // CF7 From Instance if ( $submission ) { // CF7 posted data $posted_data = $submission->get_posted_data(); } if ( !empty( $form_ID ) ) { $use_worldpay = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'use_worldpay', true ); $amount = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'amount', true ); if ( empty( $use_worldpay ) ) return; $use_worldpay = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'use_worldpay', true ); $mode_sandbox = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'mode_sandbox', true ); $debug_worldpay = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'debug', true ); $installation_id = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'installation_id', true ); $quantity = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'quantity', true ); $email = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'email', true ); $description = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'description', true ); $success_returnURL = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'success_returnurl', true ); $cancel_returnURL = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'cancel_returnurl', true ); $message = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'message', true ); $currency = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'currency', true ); add_filter( 'wpcf7_skip_mail', array( $this, 'cf7wpa_filter__wpcf7_skip_mail' ), 20 ); $amount_val = ( ( !empty( $amount ) && array_key_exists( $amount, $posted_data ) ) ? floatval( $posted_data[$amount] ) : '0' ); $quanity_val = ( ( !empty( $quantity ) && array_key_exists( $quantity, $posted_data ) ) ? floatval( $posted_data[$quantity] ) : '' ); $description_val = ( ( !empty( $description ) && array_key_exists( $description, $posted_data ) ) ? $posted_data[$description] : get_bloginfo( 'name' ) ); if ( !empty( $amount ) && array_key_exists( $amount, $posted_data ) && is_array( $posted_data[$amount] ) && !empty( $posted_data[$amount] ) ) { $val = 0; foreach ( $posted_data[$amount] as $k => $value ) { $val = $val + floatval($value); } $amount_val = $val; } if ( !empty( $quantity ) && array_key_exists( $quantity, $posted_data ) && is_array( $posted_data[$quantity] ) && !empty( $posted_data[$quantity] ) ) { $qty_val = 0; foreach ( $posted_data[$quantity] as $k => $qty ) { $qty_val = $qty_val + floatval($qty); } $quanity_val = $qty_val; } if ( empty( $amount_val ) || $amount_val < 0 ) { $_SESSION[ CF7WPA_META_PREFIX . 'amount_error' . $form_ID ] = __( 'The amount entered is blank or Invalid.', 'contact-form-7-worldpay-addon' ); return; } // Worldpay settings. Change these to your account details and the relevant URLs // for your site. if ( $mode_sandbox == '1' ): $worldpay_adr = "https://secure-test.worldpay.com/wcc/purchase"; $test = '100'; else : $worldpay_adr = "https://secure.worldpay.com/wcc/purchase"; $test = ''; endif; if( !empty( $submission->uploaded_files() ) ) { $uploaded_files = $this->cf7wpa_cf7_upload_files( $submission->uploaded_files() ); if ( !empty( $uploaded_files ) ) { foreach ( $uploaded_files as $key => $value ) { $submission->add_uploaded_file($key, serialize( $uploaded_files )); } } } // Set some example data for the payment. $amountPayable = (float) ( empty( $quanity_val ) ? $amount_val : ( $quanity_val * $amount_val ) ); $cartIdForTransiestId = time(); // Get any existing copy of our transient data if ( false === ( $postDataSaveInTransiest = get_transient( "form_data_".$cartIdForTransiestId ) ) ) { set_transient( "form_data_".$cartIdForTransiestId, $submission, 12 * HOUR_IN_SECONDS ); } // $postDataSaveInTransiest = get_transient( $cartIdForTransiestId ); $emailId = $posted_data[$email]; //$_SESSION[ CF7WPA_META_PREFIX . 'form_instance' ] = serialize( $submission ); $worldPayForm = ''; $_SESSION[ CF7WPA_META_PREFIX . 'form_worldpay' . $form_ID ] = serialize( $worldPayForm ); $_SESSION[ CF7WPA_META_PREFIX . 'form_transiest_uniq_id'] = $cartIdForTransiestId; $_SESSION[ CF7WPA_META_PREFIX . 'form_submitted_flag'] = '1'; return $submission; } } function action__cf7wpa_worldpay_save_data( $from_data, $token, $payment ) { $stored_data = ( !empty( $from_data ) ? $from_data->get_posted_data() : array() ); $form_ID = ( !empty( $from_data ) ? $from_data->get_contact_form()->id() : '' ); $exceed_wpa = sanitize_text_field( substr( get_option( '_exceed_cf7wpa_l' ), 6 ) ); if ( empty( $from_data ) ) return; $cf7wpa_post_id = wp_insert_post( array ( 'post_type' => 'cf7wpa_data', 'post_title' => ( !empty( $token ) ? $token : time() ), // Token/time 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', ) ); if ( !empty( $cf7wpa_post_id ) ) { // $stored_data = ( !empty( $from_data ) ? $from_data->get_posted_data() : array() ); // $form_ID = ( !empty( $from_data ) ? $from_data->get_contact_form()->id() : '' ); $attachent = ''; if ( !empty( $from_data->uploaded_files() ) ) { foreach ($from_data->uploaded_files() as $key => $value) { $attachent = $value; } } $currency = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'currency', true ); $amount = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'amount', true ); $quantity = get_post_meta( $form_ID, CF7WPA_META_PREFIX . 'quantity', true ); $amount_val = ( ( !empty( $amount ) && array_key_exists( $amount, $stored_data ) ) ? floatval( $stored_data[$amount] ) : '0' ); $quanity_val = ( ( !empty( $quantity ) && array_key_exists( $quantity, $stored_data ) ) ? floatval( $stored_data[$quantity] ) : '' ); if ( !empty( $amount ) && array_key_exists( $amount, $stored_data ) && is_array( $stored_data[$amount] ) && !empty( $stored_data[$amount] ) ) { $val = 0; foreach ( $stored_data[$amount] as $k => $value ) { $val = $val + floatval($value); } $amount_val = $val; } if ( !empty( $quantity ) && array_key_exists( $quantity, $stored_data ) && is_array( $stored_data[$quantity] ) && !empty( $stored_data[$quantity] ) ) { $qty_val = 0; foreach ( $stored_data[$quantity] as $k => $qty ) { $qty_val = $qty_val + floatval($qty); } $quanity_val = $qty_val; } // Get any existing copy of our transient data if ( false === ( $valuePayment = get_transient( "payment_response_".$payment['cartId'] ) ) ) { set_transient( "payment_response_".$payment['cartId'], $payment, 12 * HOUR_IN_SECONDS ); } if(!get_option('_exceed_cfwpa')){ sanitize_text_field( add_option('_exceed_cfwpa', '1') ); }else{ $exceed_val = sanitize_text_field( get_option( '_exceed_cfwpa' ) ) + 1; update_option( '_exceed_cfwpa', $exceed_val ); } if ( !empty( sanitize_text_field( get_option( '_exceed_cfwpa' ) ) ) && sanitize_text_field( get_option( '_exceed_cfwpa' ) ) > $exceed_wpa ) { $stored_data['_exceed_num_cfwpa'] = '1'; } add_post_meta( $cf7wpa_post_id, '_form_id', sanitize_text_field($form_ID) ); add_post_meta( $cf7wpa_post_id, '_payer_email', ( !empty( $payment ) ? $payment['email'] : '' ) ); add_post_meta( $cf7wpa_post_id, '_transaction_id', ( !empty( $payment["transId"] ) ? sanitize_text_field($payment["transId"]) : '' )); add_post_meta( $cf7wpa_post_id, '_invoice_no', ( !empty( $payment ) ? sanitize_text_field($payment['cartId']) : '' ) ); add_post_meta( $cf7wpa_post_id, '_amount', sanitize_text_field($amount_val) ); add_post_meta( $cf7wpa_post_id, '_quantity', sanitize_text_field($quanity_val) ); add_post_meta( $cf7wpa_post_id, '_total', ( !empty( $payment ) ? sanitize_text_field($payment['amount']) : '' ) ); add_post_meta( $cf7wpa_post_id, '_request_Ip', ( !empty( $payment ) ? str_replace( array('[', ']'), array('', ''), sanitize_text_field($payment['ipAddress']) ) : $this->getUserIpAddr() ) ); add_post_meta( $cf7wpa_post_id, '_currency', sanitize_text_field($currency) ); add_post_meta( $cf7wpa_post_id, '_form_data', (array) $stored_data ); add_post_meta( $cf7wpa_post_id, '_attachment', sanitize_text_field($attachent) ); add_post_meta( $cf7wpa_post_id, '_transaction_response', ( !empty( $payment ) ? json_encode( $payment ) : '' ) ); add_post_meta( $cf7wpa_post_id, '_transaction_status', ( (isset($payment["transId"]) && $payment["transStatus"]=='Y') ? 'Success' : 'Cancelled' ) ); } } function shortcode__worldpay_pro_success() { $transientId = $_SESSION[CF7WPA_META_PREFIX . 'form_transiest_uniq_id']; if ( empty( $transientId ) ) return '' . __( 'Something goes wrong! Please try again.', 'contact-form-7-worldpay-addon' ) . '
'; if ( true == ( $valuePayment = get_transient( "payment_response_".$transientId ) ) ) { $postSaveInTransiestPayment = get_transient( "payment_response_".$transientId ); } if ( empty( $postSaveInTransiestPayment ) ) return '' . __( 'Something goes wrong! Please try again.', 'contact-form-7-worldpay-addon' ) . '
'; // if ( true == ( $valueFormData = get_transient( "form_data_".$transientId ) ) ) { // $postSaveInTransiestFormData = get_transient( "form_data_".$transientId ); // } if ( ( $postSaveInTransiestPayment != null && (isset($postSaveInTransiestPayment["transId"]) && $postSaveInTransiestPayment["transStatus"]=='Y') ) ) { echo '| ' . __( 'Transaction Amount :', 'contact-form-7-worldpay-addon' ) . ' | '. '' . $postSaveInTransiestPayment["currency"] .' '.$postSaveInTransiestPayment["amount"] .' | '. '
|---|---|
| ' . __( 'Payment Status :', 'contact-form-7-worldpay-addon' ) . ' | '. '' . ( (isset($postSaveInTransiestPayment["transId"]) && $postSaveInTransiestPayment["transStatus"]=='Y') ? 'Success' : 'Cancelled' ) . ' | '. '
| ' . __( 'Transaction Id :', 'contact-form-7-worldpay-addon' ) . ' | '. '' . $postSaveInTransiestPayment["transId"] . ' | '. '
| ' . __( 'ERROR : Invalid response', 'contact-form-7-worldpay-addon' ) . ' | '. '|
|---|---|
| ' . __( 'Response :', 'contact-form-7-worldpay-addon' ) . ' | '. '' .' ' . __( 'Your transaction is failed or cancelled, please try again later.', 'contact-form-7-authorize-net-addon' ) . ' '. ' | '.
'
| '.__( $paymentKey, 'contact-form-7-worldpay-addon' ).' | Confirmed'.' |
| '.__( $paymentKey, 'contact-form-7-worldpay-addon' ).' | '.$paymentData.' |
| '.__( $paymentKey, 'contact-form-7-worldpay-addon' ).' | Cancelled'.' |
| '.__( $paymentKey, 'contact-form-7-worldpay-addon' ).' | '.$paymentData.' |