Listar subscripciones

Permite obtener un listado pagina de las ultimas subscripciones creadas por el comercio.

Campo

Tipo

Requerido

Descripción

merchant

string

Nombre asignado para el comercio en Payvalida. Se entrega con las credenciales.

request_id

string

id de la operación de búsqueda.

page

string

pagina de búsqueda. Valor por defecto: 1

sort

string

tipo de ordenamiento. Valores permitidos: - DESC - ASC Valor por Defecto: DESC

checksum

string

Cadena de comprobación con SHA512 (merchant+request_id+ FIXED_HASH)

Ejemplos

  • Go

package main

import (
	"bytes"
	"crypto/sha512"
	"encoding/hex"
	"fmt"
	"io/ioutil"
	"net/http"
	"time"
)

func main() {
	url := "https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions"

	merchant := "kuanto"
	request_id := "month"
	page := 1
	sort := "DESC"
	fixedHash := "FIXED_HASH"

	checksum := createChecksum(merchant, request_id, fixedHash)

	payload := []byte(fmt.Sprintf(`{
		"merchant": "%s",
		"request_id": "%s",
		"page": "%s",
		"sort": "%s",
		"checksum":"%s",
	}`, merchant, request_id, page, sort, 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, request_id, fixedHash string) string {
	checksumData := merchant + request_id + fixedHash
	hash := sha512.Sum512([]byte(checksumData))
	checksum := hex.EncodeToString(hash[:])
	return checksum
}
  • PHP

<?php
$client = new Client();
$headers = [
  'Content-Type' => 'application/json'
];

$url = 'https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions';
$merchant = 'kuanto';
$request_id = '123';
$page = 1; 
$sort = 'DESC';
$fixedHash = 'FIXED_HASH';

$checksum = createChecksum($merchant, $request_id, $fixedHash);

$body = '{
  "merchant": $merchant,
  "request_id": $request_id,
  "page": $page,
  "sort": $sort,
  "checksum": $checksum
}';
$request = new Request('POST', $url, $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();

function createChecksum($merchant, $request_id, $fixedHash)
{
    $checksumData = $merchant . $request_id . $fixedHash;
    $checksum = hash('sha512', $checksumData);
    return $checksum;
}
?>
  • Javascript

const fetch = require('node-fetch');
const crypto = require('crypto');

const url = 'https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions';
const merchant = 'kuanto';
const request_id = 'month';
const page = 1;
const sort = 'DESC';
const fixedHash = 'FIXED_HASH';

const checksumData = merchant + request_id + fixedHash;
const checksum = crypto.createHash('sha512').update(checksumData).digest('hex');

const payload = JSON.stringify({
merchant,
request_id,
page,
sort,
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);
});
  • Java

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/subscriptions/merchants/api/list/subscriptions";
        String merchant = "kuanto";
        String request_id = "123";
        String page = 1;
        String sort = "DESC";
        String fixedHash = "FIXED_HASH";

        String checksum = createChecksum(merchant, request_id, fixedHash);

        String payload = String.format("{\"merchant\": \"%s\", \"request_id\": \"%s\", \"page\": %n, \"sort\": \"%s\", \"checksum\": \"%s\"}",
                merchant, request_id, page, sort, 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 request_id, String fixedHash) {
        String checksumData = merchant + request_id + 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;
    }
}
  • Python

import requests
import hashlib
import json
import time

url = 'https://api-test.payvalida.com/subscriptions/merchants/api/list/subscriptions'
merchant = 'kuanto'
request_id = '123'
page = 1
sort = 'DESC'
fixed_hash = 'FIXED_HASH'


checksum_data = merchant + request_id + fixed_hash
checksum = hashlib.sha512(checksum_data.encode()).hexdigest()

payload = {
    'merchant': merchant,
    'request_id': request_id,
    'page': page,
    'sort': sort,
    '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)

Last updated