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("[email protected]", 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