Android Question [Solved]payment gateway help

Carlos marin

Active Member
Licensed User
Longtime User
Hello everyone

I am trying to implement a payment gateway for my clients, but I have 2 problems
First: the platform provides me with an SDK for android but it does not work for b4a

Second: they give me a script which I run anywhere and it takes me to the payment server, try to load it in the WebView and even though it generates the payment button when I click it, it does not load anything. Can you help me? I've been in this for several days and I do not know what to do, I also try WebViewExtras but I do not even load the button. Any help or indication my sincere thanks

This is the test script:

B4X:
<form>
        <script
            src="https://checkout.epayco.co/checkout.js"
            class="epayco-button"
            data-epayco-key="491d6a0b6e992cf924edd8d3d088aff1"
            data-epayco-amount="50000"
            data-epayco-name="Vestido Mujer Primavera"
            data-epayco-description="Vestido Mujer Primavera"
            data-epayco-currency="cop"
            data-epayco-country="co"
            data-epayco-test="true"
            data-epayco-external="false"
            data-epayco-response="https://ejemplo.com/respuesta.html"
            data-epayco-confirmation="https://ejemplo.com/confirmacion">
        </script>
    </form>

respond_page is the page that should load me when I click on the button

-----spanish------
Hola a todos

Estoy intentando implementar una pasarela de pagos para mis clientes, pero tengo 2 problemas
Primero: la plataforma me proporciona un SDK para android pero este no me sirve para b4a
Segundo: me dan un script el cual ejecuto en cualquier parte y me lleva al servidor de pago, intente cargar este en el webview y aunque me genera el botón de pago al darle clic no me carga nada me pueden ayudar? Llevo varios días en esto y no sé que hacer, también intente con webviewextras pero no me carga ni el botón. Cualquier ayuda o indicación mis sinceros agradecimientos
Este es el script de prueba:
 

Attachments

  • respond_page.png
    respond_page.png
    33.5 KB · Views: 459

Carlos marin

Active Member
Licensed User
Longtime User
Here is my implementation of payment API. I don't understand very well if the result are ok, but you can put real values to see if it works.
Regards
Mauro

Dear thank you very much, I've been struggling with that api too, I made a small request get and the server answered me :D:D:D

B4X:
job.Download2("https://secure.payco.co/restpagos/pse/bancos.json", Array As String("public_key", "080938ba980e6f52a883a6fcef567f7e"))

I will implement your code and I will say thank you again ;);)
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Dear thank you very much, I've been struggling with that api too, I made a small request get and the server answered me :D:D:D

B4X:
job.Download2("https://secure.payco.co/restpagos/pse/bancos.json", Array As String("public_key", "080938ba980e6f52a883a6fcef567f7e"))

I will implement your code and I will say thank you again ;);)
Pls. note that download implements GET. I think they need POST to send parameters. So DOWNLOAD is not suitable.
Ciao
Mauro
 
Upvote 0

Carlos marin

Active Member
Licensed User
Longtime User
Pls. note that download implements GET. I think they need POST to send parameters. So DOWNLOAD is not suitable.
Ciao
Mauro


Hi Tigrot! First, I have given thanks for helping me a lot. your code if it worked, when I sent the data encrypted as in this example;

B4X:
"public_key": "XXXxxx",
            "tipo_doc": "84Z9H44DIbHIbtWTAqt/5g==",
            "documento": "oki8uSkHqoR9UjkCNQZLuA==",
            "fechaExpedicion": "4fze5rCu6BhpEuEzORxPcQ==",
            "nombres": "enDmJC0lgrcfc4kXCUkApw==",
            "apellidos": "6SQR00bU4hwgpQOgRHE3Fg==",
            "email": "Xi6+dCcf1VNf+fOfdL/I489i0t3z3iR+dpJi2oYKRqo=",
            "pais": "/xj4+zt9oUQqDDhrAsxZ3g==",
            "depto": "b9WzUeEU+5dqTU+kUEC29A==",
            "ciudad": "6LdEzjnlJzetrKFyd2TwtA==",
            "telefono": "rSK+Jkfpk5xA1/yFAPGjwA==",
            "celular": "MgX2/Rg9IhsIclrR6rBcPw==",
            "direccion": "RuisJWpwvDR1/5ANPp2/6SCVeC50aUZUEH9M3u1qt1Q=",
            "ip": "dnBbYE+Iqv2Yid/XZpP43g==",
            "factura": "UyWuvm8CZ+JITVOnuzQI3w==",
            "descripcion": "HrjCJyRqc+PIniCs2cJodEoiJrP3iXHszYhAZowCuNQ=",
            "iva": "SN15iDtEvqRuqSEzIMy1uA==",
            "baseiva": "SN15iDtEvqRuqSEzIMy1uA==",
            "valor": "MkH9Jpoa8lNFWJIM3N1A6A==",
            "moneda": "BtJnH72ZhtIA8m7Tg2dq9g==",
            "tarjeta": "eNkjYyxrCOgxb9hdRxQoMq59kLD3DlG9keH1PyR8Ns8=",
            "fechaexpiracion": "TDGOhmWCw2Y+vWRWXkoM9g==",
            "codigoseguridad": "QG2ANxYV/Np6XvezGxudwQ==",
            "franquicia": "CpogvcXnoliSU4QonrYjXQ==",
            "cuotas": "wb4iJFl9GlXm7bZHX4VMSQ==",
            "url_respuesta": "tzhPnWgJOaHdH75arHBQh/DdyiJHjhC8mA8pJvYRTh4=",
            "url_confirmacion": "tzhPnWgJOaHdH75arHBQh/DdyiJHjhC8mA8pJvYRTh4=",
            "metodoconfirmacion": "JY8t3swUoHU4HV+AgyWF+Q==",
            "lenguaje": "php",
            "i": "MDAwMDAwMDAwMDAwMDAwMA==",
            "enpruebas": "vxGQj9FZusNz6NbwEzukeg=="

the entity answers me correctly. my problem is when I have to encrypt the information, the platform returns an error as if it did not send anything. I wanted to share my code and ps if I said something wrong

the platform asks me for these two conditions:
1 Send parameter i without encrypting which contains the iv or initialization vector encoded in base64
2 Encrypt the values corresponding to each request with the private key (private_key) using the encryption method AES128 in CBC mode and with a PKCS7 padding
My code: the varibles are declarated as byte; example cc(0) as byte
B4X:
Sub Button2_Click
    Dim iv(0) As Byte
    iv = Array As Byte(11, 22, 33, 44, 55, 66, 77, 88,11, 22, 33, 44, 55, 66, 77, 88) ' 16 bytes for AES
    Dim i As String
    Dim B64 As Base64
  
    i = B64.EncodeStoS(iv.Length,"UTF8")
          
    cc = EncryptText("CC", iv)
    numdoc  = EncryptText("123456789", iv)
    fexpedicion  = EncryptText("2005-01-01", iv)
    nombres = EncryptText("Camilo", iv)
    apellidos = EncryptText("Díaz", iv)
    mail = EncryptText("cliente@cliente.com", iv)
    pais = EncryptText("CO", iv)
    depto = EncryptText("Antioquia", iv)
    ciudad = EncryptText("Medellín", iv)
    telefono = EncryptText("0000000000", iv)
    celu = EncryptText("0000000000", iv)
    dir = EncryptText("Calle 67 # 23 - 22", iv)
    ip = EncryptText("186.116.10.133", iv)
    factura = EncryptText("43256", iv)
    descripcion = EncryptText("Nuevo pago de 20.000", iv)
    iva = EncryptText("0", iv)
    baseiva = EncryptText("0", iv)
    valor = EncryptText("20.000", iv)
    moneda = EncryptText("COP", iv)
    tarjeta = EncryptText("4575623182290326", iv)
    fexpiracion = EncryptText("2018-06", iv)
    codsecure = EncryptText("123", iv)
    franquicia = EncryptText("VISA", iv)
    cuotas = EncryptText("1", iv)
    url_r = EncryptText("https://www.epayco.co/respuesta", iv)
    url_com = EncryptText("https://www.epayco/callback", iv)
    metcom = EncryptText("POST", iv)
    iv_i = Bconv.StringToBytes(i, "UTF8")
    pruebas = EncryptText("true", iv)
  
    ToastMessageShow("Listo",True)

End Sub

Sub EncryptText(text As String, iv() As Byte) As Byte()

    Dim data(0) As Byte
    Dim key(0) As Byte
    Dim kg As KeyGenerator
  
    Dim c As Cipher
    c.Initialize("AES/CBC/PKCS7Padding") ' replace "DES/" with "AES/" for Rijndael or "DESEDE/" for triple DES
    c.InitialisationVector = iv
    kg.Initialize("AES")
    data = Bconv.StringToBytes(text, "UTF8")
  
    key = Bconv.StringToBytes("xxxx", "UTF8")
    kg.KeyFromBytes(key)
  
    data = c.Encrypt(data, kg.key, True)
    'Msgbox(Bconv.HexFromBytes(data), "Encryptado: " & data.Length & " bytes")
    Return data
      
End Sub

Sub peticion
  
    Dim j As HttpJob
    Dim mapjson As Map
    mapjson.Initialize
    mapjson.Put("public_key":"xxxxxxxxxxx")
    mapjson.Put("tipo_doc":cc)
    mapjson.Put("documento":numdoc)
    mapjson.Put("fechaExpedicion":fexpedicion)
    mapjson.Put("nombres":nombres)
    mapjson.Put("apellidos":apellidos)
    mapjson.Put("email":mail)
    mapjson.Put("pais":pais)
    mapjson.Put("depto":depto)
    mapjson.Put("ciudad":ciudad)
    mapjson.Put("telefono":telefono)
    mapjson.Put("celular":celu)
    mapjson.Put("direccion":dir)
    mapjson.Put("ip":ip)
    mapjson.Put("factura":factura)
    mapjson.Put("descripcion":descripcion)
    mapjson.Put("iva": iva)
    mapjson.Put("baseiva":baseiva)
    mapjson.Put("valor":valor)
    mapjson.Put("moneda":moneda)
    mapjson.Put("tarjeta":tarjeta)
    mapjson.Put("fechaexpiracion":fexpiracion)
    mapjson.Put("codigoseguridad":codsecure)
    mapjson.Put("franquicia":franquicia)
    mapjson.Put("cuotas":cuotas)
    mapjson.Put("url_respuesta":url_r)
    mapjson.Put("url_confirmacion":url_com)
    mapjson.Put("metodoconfirmacion":metcom)
    mapjson.Put("lenguaje":"php")
    mapjson.Put("i":iv_i)
    mapjson.Put("enpruebas":pruebas)
    Log("Send request")
    j.Initialize("", Me) 'name is empty as it is no longer needed
    j.PostMultipart("https://secure.payco.co/restpagos/pagos/comercios.json",mapjson,Null)
    Wait For (j) JobDone(j As HttpJob)
    Log("getresult")
    If j.Success Then
        'The result is a json string. We parse it and log the fields.
        'EditText1.Text = j.GetString
      
        Dim JSON As JSONParser
        Dim Map1 As Map
        JSON.Initialize(j.GetString)
        Map1 = JSON.NextObject
        Dim m As Map 'helper map for navigating
        m = Map1.Get("data")
        Log (Map1.Get("data"))
        'm = m.Get("popup")
      
        EditText1.Text  =  m.Get("ref_payco") & " - " & m.Get("factura")& " - " & m.Get("descripcion")& " - " & m.Get("valor") & " - " & m.Get("iva") & " - " & m.Get("baseiva") & " - " & m.Get("moneda") & " - " & m.Get("estado") _
        & " - " & m.Get("respuesta") & " - " & m.Get("autorizacion") & " - " & m.Get("recibo") & " - " & m.Get("fecha")
      
        'j.getstring is the answer from the service, scan it to get results
    Else
        Log(j.ErrorMessage)
        EditText1.Text = j.ErrorMessage
    End If
    j.Release
  
End Sub
 
Last edited:
Upvote 0

Carlos marin

Active Member
Licensed User
Longtime User
Use your routines to encode test data( the ones i put in example). Compare the result with the encoded string they provide in example(the ones you sent)

Hi tigrot, the encryption of the example I can not compare it because I do not have the private_key that is the encryption string. but that example works
I'm using the encryption library but I did not want to see if I was using the code well, I guess not, because it does not work
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I have seen that you convert the B64 string to byte. I think you have to write iv-i=i without further conversions. before sending the request.
See:
B4X:
 url_r = EncryptText("https://www.epayco.co/respuesta", iv)
    url_com = EncryptText("https://www.epayco/callback", iv)
    metcom = EncryptText("POST", iv)
   ' iv_i = Bconv.StringToBytes(i, "UTF8")
    iv_i=i 
    pruebas = EncryptText("true", iv)
 
    ToastMessageShow("Listo",True)
 
Upvote 0

Carlos marin

Active Member
Licensed User
Longtime User
Use your routines to encode test data( the ones i put in example). Compare the result with the encoded string they provide in example(the ones you sent)

hi tigrot i generate key to encrypter with the private_key here

B4X:
  key = Bconv.StringToBytes("here private key ", "UTF8")
 

Attachments

  • pay.zip
    29.7 KB · Views: 334
Upvote 0
Top