0

I'm trying to implement "Paysera" (payment system) with wordpress. Problem is, I have this callback url that gets activated once payment is made, here's the code for it:

<?php
 
require_once('lib-webtopay/WebToPay.php');
 
try {
    $response = WebToPay::checkResponse($_GET, [
        'projectid' => ######,
        'sign_password' => '#################',
    ]);
 
    if ($response['test'] !== '0') {
        throw new Exception('Testing, real payment was not made');
    }
 
    if ($response['type'] !== 'macro') {
        throw new Exception('Only macro payment callbacks are accepted');
    }
 
    $orderId = $response['orderid'];
    $amount = $response['amount'];
    $currency = $response['currency'];
    //@todo: check, if order with $orderId is already approved (callback can be repeated several times)
    //@todo: check, if order amount and currency matches $amount and $currency
    //@todo: confirm order
 
    echo 'OK';
} catch(Exception $e) {
    echo get_class($e) . ':' . $e->getMessage();
}

function update_status() {
        $data = $_GET['data'];
        header("Location: https://www.##########.lt/uzsakymo-uzskaitymas?data=$data");
        exit(); 
}
update_status();

All this code is from "Paysera"'s documentation and it works fine, but I've added the "update_status" function myself which just redirects to another url and passes the parameter. And once I run the code with it, the paysera's part doesn't work anymore and paysera itself spits out errors instead of getting a callback that payment is made successfully.

This is the response paysera gets when running this code:

<!DOCTYPE HTML> <!--[IF IE 8]> <HTML XMLNS="HTTP://WWW.W3.ORG/1999/XHTML" CLASS="IE8 WP-TOOLBAR" LANG="EN-US"> <![ENDIF]--> <!--[IF !(IE 8) ]><!--> <HTML XMLNS="HTTP://WWW.W3.ORG/1999/XHTML" CLASS="WP-TOOLBAR" LANG="EN-US"> <!--<![ENDIF]--> <HEAD> <SCRIPT TYPE="TEXT/JAVASCRIPT">IF(!GFORM){DOCUMENT.ADDEVENTLISTENER("GFORM_MAIN_SCRIPTS_LOADED",FUNCTION(){GFORM.SCRIPTSLOADED=!0}),WINDOW.ADDEVENTLISTENER("DOMCONTENTLOADED",FUNCTION(){GFORM.DOMLOADED=!0});VAR GFORM={DOMLOADED:!1,SCRIPTSLOADED:!1,INITIALIZEONLOADED:FUNCTION(O){GFORM.DOMLOADED&&GFORM.SCRIPTSLOADED?O():!GFORM.DOMLOADED&&GFORM.SCRIPTSLOADED?WINDOW.ADDEVENTLISTENER("DOMCONTENTLOADED",O):DOCUMENT.ADDEVENTLISTENER("GFORM_MAIN_SCRIPTS_LOADED",O)},HOOKS:{ACTION:{},FILTER:{}},ADDACTION:FUNCTION(O,N,R,T){GFORM.ADDHOOK("ACTION",O,N,R,T)},ADDFILTER:FUNCTION(O,N,R,T){GFORM.ADDHOOK("FILTER",O,N,R,T)},DOACTION:FUNCTION(O){GFORM.DOHOOK("ACTION",O,ARGUMENTS)},APPLYFILTERS:FUNCTION(O){RETURN GFORM.DOHOOK("FILTER",O,ARGUMENTS)},REMOVEACTION:FUNCTION(O,N){GFORM.REMOVEHOOK("ACTION",O,N)},REMOVEFILTER:FUNCTION(O,N,R){GFORM.REMOVEHOOK("FILTER",O,N,R)},ADDHOOK:FUNCTION(O,N,R,T,I){NULL==GFORM.HOOKS[O][N]&&(GFORM.HOOKS[O][N]=[]);VAR E=GFORM.HOOKS[O][N];NULL==I&&(I=N+"_"+E.LENGTH),NULL==T&&(T=10),GFORM.HOOKS[O][N].PUSH({TAG:I,CALLABLE:R,PRIORITY:T})},DOHOOK:FUNCTION(O,N,R){IF(R=ARRAY.PROTOTYPE.SLICE.CALL(R,1),NULL!=GFORM.HOOKS[O][N]){VAR T,I=GFORM.HOOKS[O][N];I.SORT(FUNCTION(O,N){RETURN O.PRIORITY-N.PRIORITY});FOR(VAR E=0;E<I.LENGTH;E++)"FUNCTION"!=TYPEOF(T=I[E].CALLABLE)&&(T=WINDOW[T]),"ACTION"==O?T.APPLY(NULL,R):R[0]=T.APPLY(NULL,R)}IF("FILTER"==O)RETURN R[0]},REMOVEHOOK:FUNCTION(O,N,R,T){IF(NULL!=GFORM.HOOKS[O][N])FOR(VAR I=GFORM.HOOKS[O][N],E=I.LENGTH-1;0<=E;E--)NULL!=T&&T!=I[E].TAG||NULL!=R&&R!=I[E].PRIORITY||I.SPLICE(E,1)}}}</SCRIPT> <TITLE>*********** - JAU GREIT!</TITLE> <META NAME='ROBOTS' CONTENT='MAX-IMAGE-PREVIEW:LARGE' /> <LINK REL='DNS-PREFETCH' HREF='//MAXCDN.BOOTSTRAPCDN.COM' /> <LINK REL='DNS-PREFETCH' HREF='//FONTS.GOOGLEAPIS.COM' /> <LINK REL='DNS-PREFETCH' HREF='//S.W.ORG' /> <LINK REL="ALTERNATE" TYPE="APPLICATION/RSS+XML" TITLE="*********** &RAQUO; FEED" HREF="HTTPS://***********.LT/FEED/" /> <LINK REL="ALTERNATE" TYPE="APPLICATION/RSS+XML" TITLE="*********** &RAQUO; COMMENTS FEED" HREF="HTTPS://***********.LT/COMMENTS/FEED/" /> <META NAME="VIEWPORT" CONTENT="WIDTH=DEVICE-WIDTH, INITIAL-SCALE=1, MAXIMUM-SCALE=1" /> <SCRIPT TYPE="TEXT/JAVASCRIPT"> WINDOW._WPEMOJISETTINGS = {"BASEURL":"HTTPS:\/\/S.W.ORG\/IMAGES\/CORE\/EMOJI\/13.0.1\/72X72\/","EXT":".PNG","SVGURL":"HTTPS:\/\/S.W.ORG\/IMAGES\/CORE\/EMOJI\/13.0.1\/SVG\/","SVGEXT":".SVG","SOURCE":{"CONCATEMOJI":"HTTPS:\/\/***********.LT\/WP-INCLUDES\/JS\/WP-EMOJI-RELEASE.MIN.JS"}}; !FUNCTION(E,A,T){VAR N,R,O,I=A.CREATEELEMENT("CANVAS"),P=I.GETCONTEXT&&I.GETCONTEXT("2D");FUNCTION S(E,T){VAR A=STRING.FROMCHARCODE;P.CLEARRECT(0,0,I.WIDTH,I.HEIGHT),P.FILLTEXT(A.APPLY(THIS,E),0,0);E=I.TODATAURL();RETURN P.CLEARRECT(0,0,I.WIDTH,I.HEIGHT),P.FILLTEXT(A.APPLY(THIS,T),0,0),E===I.TODATAURL()}FUNCTION C(E){VAR T=A.CREATEELEMENT("SCRIPT");T.SRC=E,T.DEFER=T.TYPE="TEXT/JAVASCRIPT",A.GETELEMENTSBYTAGNAME("HEAD")[0].APPENDCHILD(T)}FOR(O=ARRAY("FLAG","EMOJI"),T.SUPPORTS={EVERYTHING:!0,EVERYTHINGEXCEPTFLAG:!0},R=0;R<O.LENGTH;R++)T.SUPPORTS[O[R]]=FUNCTION(E){IF(!P||!P.FILLTEXT)RETURN!1;SWITCH(P.TEXTBASELINE="TOP",P.FONT="600 32PX ARIAL",E){CASE"FLAG":RETURN S([127987,65039,8205,9895,65039],[127987,65039,8203,9895,65039])?!1:!S([55356,56826,55356,56819],[55356,56826,8203,55356,56819])&&!S([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]);CASE"EMOJI":RETURN!S([55357,56424,8205,55356,57212],[55357,56424,8203,55356,57212])}RETURN!1}(O[R]),T.SUPPORTS.EVERYTHING=T.SUPPORTS.EVERYTHING&&T.SUPPORTS[O[R]],"FLAG"!==O[R]&&(T.SUPPORTS.EVERYTHINGEXCEPTFLAG=T.SU

If I understand it correctly, it's the header of the page I'm redirecting to within that code. So my question is, how do I sent the response that paysera is asking me to them and keep my redirect function alive? Thanks.

  • Are we talking about a client-side callback here (user gets redirected to your URL in their browser after payment), or a server-side callback (payment provider requests your URL from their servers)? If it is the latter case, then what you want is not really possible. – CBroe Jun 11 '21 at 06:28
  • It's server redirected. Damn :/ if I made redirect before whole paysera code, I suppose that latter code wouldn't run at all? Or perhaps there's a way to create like a new session so I could run other php file and this code would run tooo? – Rytis Tamošiūnas Jun 11 '21 at 06:37
  • What _exactly_ are you trying to achieve here? This URL you tried to redirect to, is that part of your site, or something external? – CBroe Jun 11 '21 at 06:38
  • Also, this is where I put url for callback.php 'file - 'callbackurl' => $self_url . '/callback.php',' Perhaps I can somehow put two URL's here so I could run my code and callback.php seperately? – Rytis Tamošiūnas Jun 11 '21 at 06:39
  • It's part of my site. I have to do two things. 1. - Callback for "paysera" to know that payment has been made. and 2. My piece of code where I update order status in my werbsite. – Rytis Tamošiūnas Jun 11 '21 at 06:40
  • Why would you need to redirect elsewhere for that? Implement the code that updates the database _in_ your callback URL script then. – CBroe Jun 11 '21 at 06:41
  • I can't. I'm using wordpress and I need to redirect to that URL so wordpress itself runs that code. – Rytis Tamošiūnas Jun 11 '21 at 06:42
  • Basically this. 1. Callback for "paysera" to know payment is made. 2. PHP file that wordpress runs so it can use it's own API's to update order status. – Rytis Tamošiūnas Jun 11 '21 at 06:44
  • You can either implement this callback URL _in_ WP to begin with (set up a Rest API endpoint), or you can “bootstrap” WordPress inside a stand-alone script, https://stackoverflow.com/questions/15304926/how-to-include-wordpress-functions-in-custom-php-file – CBroe Jun 11 '21 at 06:47
  • Perhaps you'll know. I'm not using WordPress API itself, I'm using Gravity Forms/Gravity Flow plugins. They have their own API's. If I'd load Wordpress API, would it load all plugin's API's as well? or would I need to load them seperately? – Rytis Tamošiūnas Jun 11 '21 at 06:52
  • Just tried loading wp-load.php and it works perfectly. Thank you, good man! :) – Rytis Tamošiūnas Jun 11 '21 at 06:58

0 Answers0