// ======================== // IPN Listener – mark booking as paid, send smart message // ======================== add_action( 'init', function() { if ( $_SERVER['REQUEST_URI'] == '/payfast-ipn/' && $_SERVER['REQUEST_METHOD'] == 'POST' ) { $pfData = $_POST; // Verify signature (unchanged) ksort( $pfData ); $pfOutput = ''; foreach ( $pfData as $key => $val ) { if ( $key != 'signature' && ! empty( $val ) ) { $pfOutput .= $key . '=' . urlencode( trim( $val ) ) . '&'; } } $pfOutput = rtrim( $pfOutput, '&' ); if ( ! empty( S2Y_PAYFAST_PASSPHRASE ) ) { $pfOutput .= '&passphrase=' . urlencode( S2Y_PAYFAST_PASSPHRASE ); } $our_signature = md5( $pfOutput ); if ( $our_signature == $pfData['signature'] && $pfData['payment_status'] == 'COMPLETE' ) { $booking_id = intval( $pfData['m_payment_id'] ); // Mark booking as paid update_post_meta( $booking_id, '_booking_paid', 1 ); // ---------- SMART AUTO‑MESSAGE ---------- $b = get_post( $booking_id ); $listing_id = get_post_meta( $booking_id, '_booking_listing_id', true ); $cid = get_post_meta( $booking_id, '_booking_client_id', true ); // client ID $sid = get_post_field( 'post_author', $listing_id ); // stylist ID $ltitle = get_the_title( $listing_id ); $date = get_post_meta( $booking_id, '_booking_date', true ); $time = get_post_meta( $booking_id, '_booking_time', true ); if ( $cid && $sid ) { $service_location = get_post_meta( $booking_id, '_service_location', true ); if ( $service_location === 'Salon' ) { $salon_addr = get_user_meta( $sid, '_salon_address', true ); if ( ! empty( $salon_addr ) ) { $msg2 = "Here is the salon address for your appointment:\n\n" . esc_html( $salon_addr ) . "\n\nSee you soon! – " . get_userdata( $sid )->display_name; } else { $msg2 = "Your stylist will send you the salon address shortly. Please check your messages. – " . get_userdata( $sid )->display_name; // Notify stylist to update their address $notify_msg = "A client just paid for a salon booking, but your salon address is missing. Please update it in your profile so the client receives the address."; $nid = wp_insert_post( array( 'post_type' => 's2y_message', 'post_title' => 'Missing salon address', 'post_content' => $notify_msg, 'post_status' => 'publish', 'post_author' => 0, )); if ( $nid ) { update_post_meta( $nid, '_s2y_sender_id', 0 ); update_post_meta( $nid, '_s2y_recipient_id', $sid ); } } } else { // House call – the address was given during booking, so just a friendly message $msg2 = "Hey! 👋\n\nThank you for your payment for **" . $ltitle . "**.\nI'm looking forward to our appointment on " . $date . " at " . $time . ".\n\nFeel free to message me here if you have any questions. – " . get_userdata( $sid )->display_name; } $mid = wp_insert_post( array( 'post_type' => 's2y_message', 'post_title' => 'Payment confirmed – ' . $ltitle, 'post_content' => $msg2, 'post_status' => 'publish', 'post_author' => 0, )); if ( $mid ) { update_post_meta( $mid, '_s2y_sender_id', $sid ); update_post_meta( $mid, '_s2y_recipient_id', $cid ); } } // ----------------------------------------- // ---------- EMAIL NOTIFICATIONS (optional, unchanged) ---------- $client_email = get_post_meta( $booking_id, '_client_email', true ); $stylist_email = get_userdata( $sid )->user_email; $listing_title = get_the_title( $listing_id ); $headers = array( 'Content-Type: text/html; charset=UTF-8' ); $subject = 'Payment received – ' . $listing_title; $message = "

Payment has been received for the booking of $listing_title.

"; if ( $stylist_email ) { wp_mail( $stylist_email, $subject, $message, $headers ); } if ( $client_email ) { wp_mail( $client_email, $subject, $message, $headers ); } // ------------------------------------------------------------- } exit; } }); https://style2you.shop/post-sitemap.xml 2019-02-01T00:55:49+00:00 https://style2you.shop/page-sitemap.xml 2026-07-16T02:31:28+00:00 https://style2you.shop/style_feed-sitemap.xml 2026-07-15T20:27:59+00:00 https://style2you.shop/listing-sitemap.xml 2026-07-15T22:40:58+00:00 https://style2you.shop/category-sitemap.xml 2019-02-01T00:55:49+00:00 https://style2you.shop/post_tag-sitemap.xml 2018-12-03T10:58:26+00:00 https://style2you.shop/listing_category-sitemap.xml 2026-07-15T22:40:58+00:00 https://style2you.shop/author-sitemap.xml 2026-07-06T11:23:02+00:00