Request Request (ejemplo) Response Response (ejemplo) Cabeceras
Copy curl --location --request POST 'https://api-test.payvalida.com/v4/subscriptions/plans' \
--header 'Content-Type: application/json' \
--data-raw '{
"merchant": "kuanto",
"interval": "month",
"timestamp": 1686943428,
"interval_count": "1",
"amount": "12000",
"description": "",
"checksum": "3f3c826799c2cef777b19cafe7bfa38ec7d334111a4d38f54848ba29ec2050a9ca10e945159098cea1f467b9a297643505fc9a8e2b907889376c45ab121ca3a8"
}'
Copy {
"CODE" : "0000" ,
"DESC" : "OK" ,
"DATA" : {
"id" : "1172a142-f29c-4ddb-b822-b518e9bb79cb" ,
"description" : "" ,
"interval" : "month" ,
"interval_count" : "1" ,
"amount" : "12000" ,
"method" : ""
}
}
Copy package main
import (
"bytes"
"crypto/sha512"
"encoding/hex"
"fmt"
"io/ioutil"
"net/http"
"time"
)
func main () {
url := "https://api-test.payvalida.com/v4/subscriptions/plans"
merchant := "kuanto"
interval := "month"
intervalCount := "1"
amount := "12000"
fixedHash := "FIXED_HASH"
checksum := createChecksum (merchant, amount, interval, intervalCount, fixedHash)
payload := [] byte (fmt. Sprintf ( `{
"merchant": " %s ",
"interval": " %s ",
"interval_count": " %s ",
"amount": " %s ",
"description": "",
"checksum": " %s "
}` , merchant, interval, intervalCount, amount, checksum))
req, err := http. NewRequest ( "POST" , url, bytes. NewBuffer (payload))
if err != nil {
fmt. Println ( "Error creating request:" , err)
return
}
req.Header. Set ( "Content-Type" , "application/json" )
client := & http . Client {}
resp, err := client. Do (req)
if err != nil {
fmt. Println ( "Error sending request:" , err)
return
}
defer resp.Body. Close ()
// Read response body
responseData, err := ioutil. ReadAll (resp.Body)
if err != nil {
fmt. Println ( "Error reading response body:" , err)
return
}
// Print response data
fmt. Println ( "Response:" , string (responseData))
}
func createChecksum (merchant string , amount, interval, intervalCount, fixedHash string ) string {
checksumData := merchant + amount + interval + intervalCount + fixedHash
hash := sha512. Sum512 ([] byte (checksumData))
checksum := hex. EncodeToString (hash[:])
return checksum
}
Copy <? php
$url = 'https://api-test.payvalida.com/v4/subscriptions/plans' ;
$merchant = 'kuanto' ;
$interval = 'month' ;
$intervalCount = '1' ;
$amount = '12000' ;
$fixedHash = 'FIXED_HASH' ;
$checksum = createChecksum ( $merchant , $amount , $interval , $intervalCount , $fixedHash ) ;
$data = [
'merchant' => $merchant ,
'interval' => $interval ,
'interval_count' => $intervalCount ,
'amount' => $amount ,
'description' => '' ,
'checksum' => $checksum ,
];
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n" ,
'method' => 'POST' ,
'content' => json_encode ( $data ),
] ,
];
$context = stream_context_create ( $options ) ;
$response = file_get_contents ( $url , false , $context ) ;
if ($response === false ) {
echo "Error sending request" ;
} else {
echo "Response: " . $response;
}
function createChecksum ($merchant , $amount , $interval , $intervalCount , $fixedHash)
{
$checksumData = $merchant . $amount . $interval . $intervalCount . $fixedHash;
$checksum = hash ( 'sha512' , $checksumData ) ;
return $checksum;
}
?>
Copy const fetch = require ( 'node-fetch' );
const crypto = require ( 'crypto' );
const url = 'https://api-test.payvalida.com/v4/subscriptions/plans' ;
const merchant = 'kuanto' ;
const interval = 'month' ;
const intervalCount = '1' ;
const amount = '12000' ;
const fixedHash = 'FIXED_HASH' ;
const checksumData = merchant + amount + interval + intervalCount + fixedHash;
const checksum = crypto .createHash ( 'sha512' ) .update (checksumData) .digest ( 'hex' );
const payload = JSON .stringify ({
merchant ,
interval ,
interval_count : intervalCount ,
amount ,
description : '' ,
checksum
});
fetch (url , {
method : 'POST' ,
headers : {
'Content-Type' : 'application/json' ,
} ,
body : payload ,
})
.then (response => response .text ())
.then (body => {
console .log ( 'Response:' , body);
})
.catch (error => {
console .error ( 'Error sending request:' , error);
});
Copy import java . io . BufferedReader ;
import java . io . IOException ;
import java . io . InputStreamReader ;
import java . io . OutputStream ;
import java . net . HttpURLConnection ;
import java . net . URL ;
import java . nio . charset . StandardCharsets ;
import java . security . MessageDigest ;
import java . security . NoSuchAlgorithmException ;
public class Main {
public static void main ( String [] args) {
String url = "https://api-test.payvalida.com/v4/subscriptions/plans" ;
String merchant = "kuanto" ;
String interval = "month" ;
String intervalCount = "1" ;
String amount = "12000" ;
String fixedHash = "FIXED_HASH" ;
String checksum = createChecksum(merchant , amount , interval , intervalCount , fixedHash) ;
String payload = String.format("{\"merchant\": \"%s\", \"interval\": \"%s\", \"interval_count\": \"%s\", \"amount\": \"%s\", \"description\": \"\", \"checksum\": \"%s\"}",
merchant , interval , intervalCount , amount , checksum);
try {
URL requestUrl = new URL(url) ;
HttpURLConnection connection = (HttpURLConnection) requestUrl . openConnection ();
connection . setRequestMethod ( "POST" );
connection . setRequestProperty ( "Content-Type" , "application/json" );
connection . setDoOutput ( true );
try ( OutputStream outputStream = connection . getOutputStream ()) {
byte [] input = payload . getBytes ( StandardCharsets . UTF_8 );
outputStream . write (input , 0 , input . length );
}
int responseCode = connection . getResponseCode ();
if (responseCode == HttpURLConnection . HTTP_OK ) {
try ( BufferedReader reader = new BufferedReader( new InputStreamReader( connection . getInputStream())) ) {
String line;
StringBuilder response = new StringBuilder() ;
while ((line = reader . readLine ()) != null ) {
response . append (line);
}
System . out . println ( "Response: " + response . toString ());
}
} else {
System . out . println ( "Error: " + responseCode);
}
connection . disconnect ();
} catch ( IOException e) {
e . printStackTrace ();
}
}
public static String createChecksum ( String merchant , String amount , String interval , String intervalCount
String fixedHash) {
String checksumData = merchant + amount + interval + intervalCount + fixedHash;
try {
MessageDigest digest = MessageDigest . getInstance ( "SHA-512" );
byte [] hashBytes = digest . digest ( checksumData . getBytes ( StandardCharsets . UTF_8 ));
StringBuilder hexString = new StringBuilder() ;
for ( byte hashByte : hashBytes) {
String hex = Integer . toHexString ( 0xff & hashByte);
if ( hex . length () == 1 ) {
hexString . append ( '0' );
}
hexString . append (hex);
}
return hexString . toString ();
} catch ( NoSuchAlgorithmException e) {
e . printStackTrace ();
}
return null ;
}
}
Copy import requests
import hashlib
import json
import time
url = 'https://api-test.payvalida.com/v4/subscriptions/plans'
merchant = 'kuanto'
interval = 'month'
intervalCount = '1'
amount = '12000'
fixed_hash = 'FIXED_HASH'
checksum_data = merchant + amount + interval + intervalCount + fixed_hash
checksum = hashlib . sha512 (checksum_data. encode ()). hexdigest ()
payload = {
'merchant' : merchant ,
'interval' : interval ,
'interval_count' : intervalCount ,
'amount' : amount ,
'description' : '' ,
'checksum' : checksum
}
headers = {
'Content-Type' : 'application/json'
}
response = requests . post (url, headers = headers, data = json. dumps (payload))
if response . status_code == 200 :
print ( 'Response:' , response.text)
else :
print ( 'Error:' , response.status_code)