• Resolved pmonty

    (@pmonty)


    So I have a new code snippet and at the bottom of that it has the following code to actually call it

    
    if (!empty($_POST['paynow'])) {
        //Generate signature (see Custom Integration -> Step 2)
        $data["signature"] = generateSignature($data, $passPhrase);
    
        //Convert the data array to a string
        $pfParamString = dataToString($data);
    
        //Generate payment identifier
        $identifier = generatePaymentIdentifier($pfParamString);
    
        if ($identifier !== null) {
            echo '<script type="text/javascript">window.payfast_do_onsite_payment({"uuid":"' . $identifier . '"}, function (result) {
                if (result === true) {
    		 		// Payment Completed
                }
                else {
                  	// Payment Window Closed
                }
              });</script>';
        }
    }

    I am wondering if there is a way to call this code from the front end. Can’t really be a submit button I guess because I don’t want the form to continue to the next step and at the same time I need the code to execute which actually makes a modal popup.

    Happy to change the if statement if needed.

    Any tips or ideas no matter how helpful would be incredible!

Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    The easiest method would probably be to create a shortcode:

    add_shortcode( 'payment_modal', function () {
    	ob_start();
    
    	// do output here
    
    	return ob_get_clean();
    } );

    Once added, you can just use the [payment_modal] shortcode in a post.

Viewing 1 replies (of 1 total)

The topic ‘Execute code snippet from button’ is closed to new replies.