Codigo Groovy

package ptp import com.placetopay.java_placetopay.Entities.Models.RedirectRequest import com.placetopay.java_placetopay.Entities.Models.RedirectResponse import com.placetopay.java_placetopay.PlaceToPay import sun.net.www.http.HttpClient import java.security.MessageDigest import java.security.NoSuchAlgorithmException import java.security.SecureRandom import java.text.SimpleDateFormat import org.apache.commons.codec.binary.Hex import org.apache.http.HttpResponse import org.apache.http.NameValuePair import org.apache.http.client.HttpClient import org.apache.http.client.entity.UrlEncodedFormEntity import org.apache.http.client.methods.HttpGet import org.apache.http.client.methods.HttpPost import org.apache.http.impl.client.HttpClientBuilder import org.apache.http.message.BasicNameValuePair class PlaceToPayController { def url = "https://test.placetopay.ec/redirection/" def login = "8893c3501c96ece3d3ee14cf7f273b84" def secretKey = "22dx62Xa1c7GmMrl" def nonce = "" def seed = "" def tranKey = "" PlaceToPayController(){ nonce = new BigInteger(130, new SecureRandom()).toString() seed = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ", Locale.getDefault())).format(new Date()) nonce = getNonce() tranKey = getTranKey() } def index() { def payload = '"locale": "es_EC",' + ' "payer": {' + ' "name": "Kellie Gerhold",' + ' "surname": "Yost",' + ' "email": "flowe@anderson.com",' + ' "documentType": "CC",' + ' "document": "1848839248",' + ' "mobile": "3006108300",' + ' "address": {' + ' "street": "703 Dicki Island Apt. 609",' + ' "city": "North Randallstad",' + ' "state": "Antioquia",' + ' "postalCode": "46292",' + ' "country": "US",' + ' "phone": "363-547-1441 x383"' + ' }' + ' },' + ' "buyer": {' + ' "name": "Kellie Gerhold",' + ' "surname": "Yost",' + ' "email": "flowe@anderson.com",' + ' "documentType": "CC",' + ' "document": "1848839248",' + ' "mobile": "3006108300",' + ' "address": {' + ' "street": "703 Dicki Island Apt. 609",' + ' "city": "North Randallstad",' + ' "state": "Antioquia",' + ' "postalCode": "46292",' + ' "country": "US",' + ' "phone": "363-547-1441 x383"' + ' }' + ' },' + ' "payment": {' + ' "reference": "reference",' + ' "description": "Iusto sit et voluptatem.",' + ' "amount": {' + ' "taxes": [' + ' {' + ' "kind": "ice",' + ' "amount": "56.4",' + ' "base": "470"' + ' },' + ' {' + ' "kind": "valueAddedTax",' + ' "amount": "89.3",' + ' "base": "470"' + ' }' + ' ],' + ' "details": [' + ' {' + ' "kind": "shipping",' + ' "amount": "47"' + ' },' + ' {' + ' "kind": "tip",' + ' "amount": "47"' + ' },' + ' {' + ' "kind": "subtotal",' + ' "amount": "940"' + ' }' + ' ],' + ' "currency": "USD",' + ' "total": "1076.3"' + ' },' + ' "items": [' + ' {' + ' "sku": "26443",' + ' "name": "Qui voluptatem excepturi.",' + ' "category": "physical",' + ' "qty": "1",' + ' "price": "940",' + ' "tax": "89.3"' + ' }' + ' ],' + ' "shipping": {' + ' "name": "Kellie Gerhold",' + ' "surname": "Yost",' + ' "email": "flowe@anderson.com",' + ' "documentType": "CC",' + ' "document": "1848839248",' + ' "mobile": "3006108300",' + ' "address": {' + ' "street": "703 Dicki Island Apt. 609",' + ' "city": "North Randallstad",' + ' "state": "Antioquia",' + ' "postalCode": "46292",' + ' "country": "US",' + ' "phone": "363-547-1441 x383"' + ' }' + ' },' + ' "allowPartial": false' + ' },' + ' "expiration": "2018-05-03",' + ' "ipAddress": "127.0.0.1",' + ' "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36",' + ' "returnUrl": "http://dnetix.dev/p2p/client",' + ' "cancelUrl": "https://dnetix.co",' + ' "skipResult": false,' + ' "noBuyerFill": false,' + ' "captureAddress": false,' + ' "paymentMethod": null' def request = '{' + '"auth": {' + '"login":' + '"' + login + '",' + '"seed":' + '"' + seed + '",' + '"nonce":' + '"' + nonce + '",' + '"tranKey":' + '"' + tranKey + '"' + '}' + ',' + payload + '}' String data = '{"locale":"es_EC","payer":{"name":"Kellie Gerhold","surname":"Yost","email":"flowe@anderson.com","documentType":"CC","document":"1848839248","mobile":"3006108300","address":{"street":"703 Dicki Island Apt. 609","city":"North Randallstad","state":"Antioquia","postalCode":"46292","country":"US","phone":"363-547-1441 x383"}},"buyer":{"name":"Kellie Gerhold","surname":"Yost","email":"flowe@anderson.com","documentType":"CC","document":"1848839248","mobile":"3006108300","address":{"street":"703 Dicki Island Apt. 609","city":"North Randallstad","state":"Antioquia","postalCode":"46292","country":"US","phone":"363-547-1441 x383"}},"payment":{"reference":"reference","description":"Iusto sit et voluptatem.","amount":{"taxes":[{"kind":"ice","amount":"56.4","base":"470"},{"kind":"valueAddedTax","amount":"89.3","base":"470"}],"details":[{"kind":"shipping","amount":"47"},{"kind":"tip","amount":"47"},{"kind":"subtotal","amount":"940"}],"currency":"USD","total":"1076.3"},"items":[{"sku":"26443","name":"Qui voluptatem excepturi.","category":"physical","qty":"1","price":"940","tax":"89.3"}],"shipping":{"name":"Kellie Gerhold","surname":"Yost","email":"flowe@anderson.com","documentType":"CC","document":"1848839248","mobile":"3006108300","address":{"street":"703 Dicki Island Apt. 609","city":"North Randallstad","state":"Antioquia","postalCode":"46292","country":"US","phone":"363-547-1441 x383"}},"allowPartial":false},"expiration":"2018-05-02","ipAddress":"127.0.0.1","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36","returnUrl":"http://dnetix.dev/p2p/client","cancelUrl":"https://dnetix.co","skipResult":false,"noBuyerFill":false,"captureAddress":false,"paymentMethod":"null"}' /* PlaceToPay gateway = new com.placetopay.java_placetopay.PlaceToPay( "8893c3501c96ece3d3ee14cf7f273b84", "22dx62Xa1c7GmMrl", new URL(url) ) RedirectRequest req = new RedirectRequest(data) RedirectResponse response = gateway.request(req) if (response.isSuccessful()) { // STORE THE response.getRequestId() and response.getProcessUrl() on your DB associated with the payment order // Redirect the client to the processUrl or display it on the JS extension String redirectTo = response.getProcessUrl() } else { // There was some error so check the message and log it response.getStatus().getMessage() } */ request = '{"locale":"es_CO","buyer":{"name":"Travon Herzog","surname":"Little","email":"cecile97@boyer.com","documentType":"CC","document":"4506783802","mobile":"3006108300","address":{"street":"96831 Mekhi Island Apt. 005","city":"East Eleazar","state":"Antioquia","postalCode":"61082","country":"CO","phone":"+13806013012"}},"payment":{"reference":"TEST_20180502_163546","description":"Qui voluptas officia quia quis quidem maxime velit.","amount":{"taxes":[{"kind":"ice","amount":4.2,"base":35},{"kind":"valueAddedTax","amount":6.65,"base":35}],"details":[{"kind":"shipping","amount":1.75},{"kind":"tip","amount":1.75},{"kind":"subtotal","amount":35}],"currency":"USD","total":49.35},"items":[{"sku":30519,"name":"Sed est.","category":"physical","qty":1,"price":35,"tax":6.65}],"shipping":{"name":"Travon Herzog","surname":"Little","email":"cecile97@boyer.com","documentType":"CC","document":"4506783802","mobile":"3006108300","address":{"street":"96831 Mekhi Island Apt. 005","city":"East Eleazar","state":"Antioquia","postalCode":"61082","country":"CO","phone":"+13806013012"}},"allowPartial":false},"expiration":"2018-05-03T16:35:46-05:00","ipAddress":"167.160.172.10","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36","returnUrl":"https://dnetix.co/p2p/client","cancelUrl":"https://dnetix.co","skipResult":false,"noBuyerFill":false,"captureAddress":false,"paymentMethod":null,"fields":[{"keyword":"Redeem Code","value":548149,"displayOn":"payment"}],"auth":{"login":"8893c3501c96ece3d3ee14cf7f273b84","tranKey":"o0QmUAXeLs03iy9OeWivsfCcRk8=","nonce":"TVdVMU5tTTFPRGc0WmpNMU16Sm1Nakl5WVRKa05qSXdPR1ppTnpabE1UTT0=","seed":"2018-05-02T16:35:53-05:00"}}' HttpClient client = HttpClientBuilder .create() .build() HttpPost post = new HttpPost(url + "api/session") post.setHeader("User-Agent","Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/13.0 Firefox/13.0") List<NameValuePair> urlParameters = new ArrayList<NameValuePair>() urlParameters.add(new BasicNameValuePair("json", request)) post.setEntity(new UrlEncodedFormEntity(urlParameters)) HttpResponse response = client.execute(post) println("Test") } def pago() { } def procesar(){ } def response(){ } String getTranKey() { try { return base64(sha1(nonce + seed + secretKey)) } catch (NoSuchAlgorithmException e) { return null } } String getBasicTranKey() { try { return sha1String(seed + secretKey) } catch (NoSuchAlgorithmException e) { return null } } String getNonce() { return base64(nonce.getBytes()) } static byte[] sha1(String input) throws NoSuchAlgorithmException { MessageDigest mDigest = MessageDigest.getInstance("SHA1") return mDigest.digest(input.getBytes()) } String sha1String(String input) throws NoSuchAlgorithmException { MessageDigest mDigest = MessageDigest.getInstance("SHA1") byte[] result = mDigest.digest(input.getBytes()) StringBuffer sb = new StringBuffer() for (int i = 0; i < result.length; i++) { sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)) } return sb.toString() } def String base64(byte[] input) { byte[] encodedBytes = (Base64.getEncoder()).encode(input) return new String(encodedBytes) } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.