query_vars, get_the_permalink() . '?better_payment_paypal_status=success&better_payment_widget_id=' . $widget_id ); $cancel_url = add_query_arg( $wp->query_vars, get_the_permalink() . '?better_payment_error_status=error&better_payment_widget_id=' . $widget_id ); ob_start(); $error_info = [ 'business_email' => !empty($settings['better_payment_paypal_business_email']) ]; ?> bp_allowed_tags() ); } /** * Paystack button * * @since 0.0.1 */ public static function paystack_button( $widget_id = '' , $settings = []) { $paystack_button_text = ! empty( $settings["better_payment_form_form_buttons_paystack_button_text"] ) ? $settings["better_payment_form_form_buttons_paystack_button_text"] : __('Proceed to Payment', 'better-payment'); ob_start(); ?> bp_allowed_tags() ); } public static function hide_show_payment_button_class( $settings, $type = 'paypal' ){ $button_hidden_class = 'is-hidden'; $types = ['paypal', 'stripe', 'paystack']; if( ! in_array($type, $types) ){ return $button_hidden_class; } $is_type_enable = ! empty( $settings[ "better_payment_form_{$type}_enable" ] ) && 'yes' === $settings[ "better_payment_form_{$type}_enable" ]; if( ! $is_type_enable ){ return $button_hidden_class; } $is_paypal_enable = ! empty( $settings[ "better_payment_form_paypal_enable" ] ) && 'yes' === $settings[ "better_payment_form_paypal_enable" ]; $is_stripe_enable = ! empty( $settings[ "better_payment_form_stripe_enable" ] ) && 'yes' === $settings[ "better_payment_form_stripe_enable" ]; $is_paystack_enable = ! empty( $settings[ "better_payment_form_paystack_enable" ] ) && 'yes' === $settings[ "better_payment_form_paystack_enable" ]; switch( $type ){ case 'paypal': $button_hidden_class = ''; break; case 'stripe': if( ( ! $is_paypal_enable ) ){ $button_hidden_class = ''; } break; case 'paystack': if( ( ! $is_paypal_enable ) && ( ! $is_stripe_enable ) ){ $button_hidden_class = ''; } break; default: break; } return $button_hidden_class; } /** * Payment create in db * * @since 0.0.1 */ public static function payment_create( $data ) { global $wpdb; $table = "{$wpdb->prefix}better_payment"; $wpdb->insert( $table, $data ); if ( $wpdb->insert_id ) { return $wpdb->insert_id; } else { return false; } } /** * Mamage response * * @since 0.0.1 */ public static function manage_response( $settings = [], $widget_id = '' ) { $status = false; //if widget id is different then return false if ( !empty( $_REQUEST[ 'better_payment_widget_id' ] ) && $_REQUEST[ 'better_payment_widget_id' ] !== $widget_id ) { return $status; } if ( !empty( $_REQUEST[ 'better_payment_error_status' ] ) ) { self::failed_message_template( $settings ); $redirection_url_error = ! empty( $settings['better_payment_form_error_page_url']['url'] ) ? esc_url( $settings['better_payment_form_error_page_url']['url'] ) : ''; if( $redirection_url_error ){ ?> prefix}better_payment"; $results = $wpdb->get_row( $wpdb->prepare( "SELECT id,form_fields_info,referer FROM $table WHERE order_id=%s and status is NULL limit 1", sanitize_text_field( $_REQUEST[ 'item_number' ] ) ) ); if ( !empty( $results->id ) ) { $updated = $wpdb->update( $table, array( 'transaction_id' => sanitize_text_field( $data[ 'txn_id' ] ), 'status' => sanitize_text_field( $data[ 'payment_status' ] ), 'email' => sanitize_email( $data[ 'payer_email' ] ), 'customer_info' => maybe_serialize( $data ), ), array( 'ID' => $results->id ) ); if ( false !== $updated ) { //Send email notification if ( ( isset($settings[ 'better_payment_form_email_enable' ]) && $settings[ 'better_payment_form_email_enable' ] == 'yes' ) || ( $results->referer === 'elementor-form' ) ) { self::better_email_notification(sanitize_text_field( $data[ 'txn_id' ] ), sanitize_email( $data[ 'payer_email' ] ), $settings, 'PayPal', $results->form_fields_info); } return sanitize_text_field( $data[ 'txn_id' ] ); } } }else if($data['better_payment_paypal_status'] === 'success'){ return ( isset($data[ 'txn_id' ]) && !empty( sanitize_text_field( $data[ 'txn_id' ] ) ) ) ? sanitize_text_field( $data[ 'txn_id' ] ) : __('Payment under processing!', 'better-payment'); } return false; } /** * Stripe payment success * * @since 0.0.1 */ public static function stripe_payment_success( $settings = [] ) { $data = $_REQUEST; if ( !empty( $data[ 'better_payment_stripe_id' ] ) ) { global $wpdb; $table = "{$wpdb->prefix}better_payment"; $results = $wpdb->get_row( $wpdb->prepare( "SELECT id,obj_id,transaction_id,form_fields_info,referer FROM $table WHERE order_id=%s and status = 'unpaid' limit 1", sanitize_text_field( $data[ 'better_payment_stripe_id' ] ) ) ); if ( !empty( $results->obj_id ) && !empty( $settings[ 'better_payment_stripe_secret_key' ] ) ) { $header = array( 'Authorization' => 'Basic ' . base64_encode( sanitize_text_field( $settings[ 'better_payment_stripe_secret_key' ] ) . ':' ), 'Stripe-Version' => '2019-05-16', ); $request = [ 'expand' => [ 'subscription.latest_invoice.payment_intent', 'payment_intent' ] ]; $response = wp_safe_remote_post( 'https://api.stripe.com/v1/checkout/sessions/' . $results->obj_id, array( 'method' => 'GET', 'headers' => $header, 'timeout' => 70, 'body' => $request ) ); if ( is_wp_error( $response ) || empty( $response[ 'body' ] ) ) { return new \WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'better-payment' ) ); } $response = json_decode( $response[ 'body' ] ); if ( isset( $response->error->message ) ) { return new \WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'better-payment' ) ); } $updated = $wpdb->update( $table, array( 'status' => sanitize_text_field( $response->payment_status ), 'email' => sanitize_email( current( $response->payment_intent->charges->data )->billing_details->email ), 'customer_info' => maybe_serialize( $response ), ), array( 'ID' => $results->id ) ); if ( false !== $updated ) { //Send email notification $better_customer_email = sanitize_email( current( $response->payment_intent->charges->data )->billing_details->email ); if ( (isset($settings[ 'better_payment_form_email_enable' ]) && $settings[ 'better_payment_form_email_enable' ] == 'yes' ) || ( $results->referer === 'elementor-form' ) ) { self::better_email_notification($results->transaction_id, $better_customer_email, $settings, 'Stripe', $results->form_fields_info); } return $results->transaction_id; } } } return false; } /** * Paystack payment success * * @since 0.0.1 */ public static function paystack_payment_success( $settings = [] ) { $data = $_REQUEST; if ( ! empty( $data[ 'better_payment_paystack_id' ] ) ) { global $wpdb; $table = "{$wpdb->prefix}better_payment"; $results = $wpdb->get_row( $wpdb->prepare( "SELECT id,obj_id,transaction_id,form_fields_info,referer FROM $table WHERE order_id=%s and status = 'unpaid' limit 1", sanitize_text_field( $data[ 'better_payment_paystack_id' ] ) ) ); $header_info = array( 'Authorization' => 'Bearer ' . sanitize_text_field( $settings[ 'better_payment_paystack_secret_key' ] ), "Cache-Control: no-cache", ); $response = wp_safe_remote_get( 'https://api.paystack.co/transaction/verify/'. sanitize_text_field( $data[ 'reference' ] ), array( 'headers' => $header_info, 'timeout' => 70, ) ); $response = json_decode(wp_remote_retrieve_body($response)); if ( ! empty( $response->status ) ) { $updated = $wpdb->update( $table, array( 'status' => ! empty( $response->data->status ) ? sanitize_text_field( $response->data->status ) : '', 'amount' => ! empty( $response->data->amount ) ? floatval( $response->data->amount ) : 0, 'obj_id' => ! empty( $response->data->id ) ? sanitize_text_field( $response->data->id ) : '', 'transaction_id' => ! empty( $response->data->reference ) ? sanitize_text_field( $response->data->reference ) : '', 'customer_info' => ! empty( $response->data->customer ) ? maybe_serialize( $response->data->customer ) : '', 'email' => ! empty( $response->data->customer->email ) ? sanitize_email( $response->data->customer->email ) : '', ), array( 'ID' => $results->id ) ); } $better_customer_email = ! empty( $response->data->customer->email ) ? maybe_serialize( $response->data->customer->email ) : ''; $transaction_id = ! empty( $response->data->reference ) ? sanitize_text_field( $response->data->reference ) : ''; if ( ! empty( $updated ) && $better_customer_email ) { //Send email notification if ( (isset($settings[ 'better_payment_form_email_enable' ]) && $settings[ 'better_payment_form_email_enable' ] == 'yes' ) || ( $results->referer === 'elementor-form' ) ) { self::better_email_notification($transaction_id, $better_customer_email, $settings, 'Stripe', $results->form_fields_info); } return $transaction_id; } } return false; } /** * Get currency symbols * * @since 0.0.1 */ public static function get_currency_symbols( $currency = 'USD' ) { $list = [ 'USD' => "$", 'EUR' => "€", 'GBP' => "£", 'AED' => "د.إ", 'AUD' => "$", 'CAD' => "$", 'CZK' => "Kč", 'DKK' => "kr", 'HKD' => "$", 'HUF' => "ft", 'ILS' => "₪", 'JPY' => "¥", 'MXN' => "$", 'NOK' => "kr", 'NZD' => "$", 'PHP' => "₱", 'PLN' => "zł", 'RUB' => "₽", 'SGD' => "$", 'SEK' => "kr", 'CHF' => "CHF", 'TWD' => "$", 'THB' => "฿", 'TRY' => "₺", 'ZAR' => "R", ]; return !empty( $list[ $currency ] ) ? $list[ $currency ] : '$'; } /** * Success message template * * @since 0.0.1 */ public static function success_message_template( $settings = [], $tr_id = '' ) { if ( empty( $tr_id ) || is_wp_error($tr_id)) { return false; } wp_enqueue_script('better-payment-admin-script'); $image_url = BETTER_PAYMENT_ASSETS . '/img/success.svg'; $show_icon = 0; if ( !empty( $settings[ 'better_payment_form_success_message_icon' ][ 'library' ] ) ) { if ( $settings[ 'better_payment_form_success_message_icon' ][ 'library' ] == 'svg' ) { $image_url = $settings[ 'better_payment_form_success_message_icon' ][ 'value' ][ 'url' ]; } else { $show_icon = 1; $image_url = $settings[ 'better_payment_form_success_message_icon' ][ 'value' ]; } } ?>
%s", ( isset( $settings['better_payment_form_success_message_transaction'] ) ) ? esc_html__( $settings['better_payment_form_success_message_transaction'], 'better-payment' ) : esc_html__('Transaction Number', 'better-payment'), esc_html( $tr_id ) );; ?>