NetTalk Central

Author Topic: Redirect URL received after POST, how to handle (YOCO)  (Read 152 times)

JohanR

  • Sr. Member
  • ****
  • Posts: 342
    • View Profile
    • Email
Redirect URL received after POST, how to handle (YOCO)
« on: May 10, 2024, 02:31:13 AM »
Hi,

I am currently trying to implement a new secure credit card payment system, YOCO

It's a 2 step process, initiated by a POST, with the bearer security, amount, currency and then on the success of the POST,
one of the return data fields is a redirect URL ,
which I must direct the user to.
This redirected URL is a page on the providor site, where the user will enter CC, Expiry etc,
on success/fail/cancel , one of my URL will be called


Question is how to handle the re-direct after the receipt of the successful POST?


TIA for any info

Johan





JohanR

  • Sr. Member
  • ****
  • Posts: 342
    • View Profile
    • Email
Re: Redirect URL received after POST, how to handle (YOCO)
« Reply #1 on: May 10, 2024, 03:55:17 AM »
Hi,

Plan I'm going with, if I missing the obvious let me know.

Memory NetWebform 
In the generate form , call a hidden NetWebClient procedure that handles the POST and return URL to NetWebForm

On the NetWebform, display fields for confirmation and a PAY button with the URL returned by the NetWebClient
If client clicks the button, then they will redirected to the CC Payment page 

If there are other ways to handle this, please let me know

Johan

 

osquiabro

  • Hero Member
  • *****
  • Posts: 677
    • View Profile
    • Email
Re: Redirect URL received after POST, how to handle (YOCO)
« Reply #2 on: May 10, 2024, 04:35:51 AM »
is the correct way, this is an example for the old Stripe API, the new API is a little more difficult, but the Yoco API is similar to the old Stripe API, you can convert this code to NT curl and avoid using NetWebClient. By the way, I never used nt curl but I think it's similar to Mike Duglas' curl

SendRequest         ROUTINE
DATA
curl        TCurlHttpClass
res CURLcode
qIndex      LONG, AUTO
respBuffer  STRING(65000) !big enuff to hold received response

CODE   
   
    curl.Init()
    curl.FreeHttpHeaders()   
    SSLInfo:bUseSSL = TRUE
    p_web.ssv('PaymentFrom','Afiliacion')
   
    IF SSLInfo:bUseSSL         
        res = curl.SetSSLVerifyHost(SSLInfo:bVerifyHost)
        IF res <> CURLE_OK
           
        END
        res = curl.SetSSLVerifyPeer(SSLInfo:bVerifyPeer)
        IF res <> CURLE_OK
           
        END
        res = curl.SetSSLVersion(SSLInfo:Version)
        IF res <> CURLE_OK
           
        END
        IF SSLInfo:Certificate
            res = curl.SetCAInfo(SSLInfo:Certificate)
            IF res <> CURLE_OK
             
            END
        END
    END   
    curl.SetCustomRequest('POST')
        !-H "Content-Type: application/json"       
        !-H "Authorization: Bearer Access-Token"
    CASE p_Web.gsv('Com:PaymentEnviroment')               
        OF 'sandbox'
            curl.AddHttpHeader('Authorization: Bearer '&p_web.gsv('Com:StripteSandBoxToken'))
        OF 'production'
            curl.AddHttpHeader('Authorization: Bearer '&p_web.gsv('Com:StripteProductionToken'))
    END   
        !-- applies http headers added by AddHttpHeader calls
    curl.SetHttpHeaders()
       !----Create a Token --------!
    Send:Url = 'https://api.stripe.com/v1/tokens'
    Send:PostParams ='card[number]='&p_web.gsv('CardNumber')&'&card[exp_month]='&p_web.GSV('ExpMonth')&'&card[exp_year]='&p_web.GSV('ExpYear')&'&card[cvc]='&p_web.GSV('Cvv')
        !----Create a Token -------!   
           
    CLEAR(TokenError)
    CLEAR(Token)   
    res = curl.SendRequestStr(Send:Url, Send:PostParams, respBuffer)     
    Loc:CantidadaPagarSend = p_web.gsv('Loc:CantidadaPagar')*100
       
    IF res = CURLE_OK       
        jsonStr = CLIP(respBuffer) 
       
        DO ParseJSON               
        IF Token<>'' AND TokenError='' 
            CLEAR(pJsonString)
            curl.FreeHttpHeaders()
            curl.SetCustomRequest('POST')           
            CASE p_web.gsv('Com:PaymentEnviroment')               
                OF 'sandbox'
                    curl.AddHttpHeader('Authorization: Bearer '&p_web.gsv('Com:StripteSandBoxToken'))
                OF 'production'
                    curl.AddHttpHeader('Authorization: Bearer '&p_web.gsv('Com:StripteProductionToken'))
            END
           
            curl.SetHttpHeaders()
            Send:Url = 'https://api.stripe.com/v1/charges'           
            Send:PostParams ='currency=usd&amount='&p_web.gsv('Loc:CantidadaPagar')*100&'&description=charge&source='&clip(Token)&'&receipt_email='&p_web.gsv('Use:EMAIL')&'&metadata[afiliacionid]='&p_web.gsv('AfiliacionId')
           
            res = curl.SendRequestStr(Send:Url, Send:PostParams, respBuffer)                       
            IF res = CURLE_OK               
                pJsonString = CLIP(respBuffer)                 
                DO ParseJSON2
                IF TokenError<>''
                    loc:alert = TokenError
                    p_web.SetValue('SelectField','CardNumber')
                    EXIT
                END
                Loc:Status=1
                DO AddPayment
                do Refresh::b1
                DO SendEmail
                p_web.Script( p_web.WindowOpen( 'PaymentSucessfull' ))
            END           
        ELSE           
            loc:alert = CLIP(TokenError)
            p_web.SetValue('SelectField','NameonCard')
            EXIT           
        END   
    ELSIF res = -1
        loc:alert = 'Cannot open local file Contact System Administrator'
        p_web.SetValue('SelectField','NameonCard')       
    ELSE
        loc:alert = 'SendRequest failed2: '& curl.StrError(res)&' Contact System Administrator'
        p_web.SetValue('SelectField','NameonCard')       
    END

Alberto

  • Hero Member
  • *****
  • Posts: 1849
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Redirect URL received after POST, how to handle (YOCO)
« Reply #3 on: May 10, 2024, 05:18:16 AM »
JohanR,
I would call the NtWebClient before the memory form call, if you call it in the generate form it will be called many times.
And you can use a media field in the memory form to include the CC form (using its url) in your page.
Hope this helps
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11194
    • View Profile
Re: Redirect URL received after POST, how to handle (YOCO)
« Reply #4 on: May 12, 2024, 11:27:39 PM »

Plan I'm going with, if I missing the obvious let me know.
 

This is the approach I would adopt, and indeed the approach I think they recommend.

Bruce

JohanR

  • Sr. Member
  • ****
  • Posts: 342
    • View Profile
    • Email
Re: Redirect URL received after POST, how to handle (YOCO)
« Reply #5 on: May 13, 2024, 06:30:46 AM »
Hi,

Thanks for replies and advice,
Have it working quite nicely.

regards

Johan