Registrar Plan
Permite registrar un plan de cobro con la periodicidad de la suscripción y recordatorio de pago oportuno hacia el usuario
Método: POST
Producción: https://api.payvalida.com/v4/subscriptions/plans
Campo
Tipo
Requerido
Descripción
merchant
string
sí
Nombre asignado para el comercio en Payvalida. Se entrega con las credenciales.
interval
string
sí
La frecuencia con la que se paga un plan. Valores permitidos: - month - week - day
interval_count
string
sí
El número de intervalos (especificados en el atributo interval) entre los pagos del plan. Por ejemplo, si interval=month e interval_count=1, se pagará mensualmente. Si interval=month e interval_count=3, se pagará cada 3 meses. Si interval=week e interval_count=1, se pagará semanalmente.
amount
string
sí
Valor del plan. Puede tener máximo 2 números decimales.
description
string
sí
Descripción corta del plan. No incluir caracteres especiales.
method
string
no
checksum
string
sí
Cadena de comprobación con SHA512 (merchant+amount+interval+interval_count+ FIXED_HASH)
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"
}'
Campo
Estructura
Tipo
Descripción
CODE
-
string
Código de respuesta 0000 para OK.
DESC
-
string
Descripción de la respuesta.
DATA
-
string
Datos del registro
id
DATA
string
id generado para el plan, es usado para asignar una suscripcion a un cliente
interval
DATA
string
Periodicidad que se facturará. debe tener el valor de "month"
interval_count
DATA
string
Frecuencia de recaudo
amount
DATA
string
Monto para el recaudo. Puede tener maximo 2 numeros decimales
description
DATA
string
Descripción corta del plan. No incluir caracteres especiales.
method
DATA
string
{
"CODE":"0000",
"DESC":"OK",
"DATA":{
"id":"1172a142-f29c-4ddb-b822-b518e9bb79cb",
"description":"",
"interval":"month",
"interval_count":"1",
"amount":"12000",
"method":""
}
}
Cabecera
Valor
Content-Type
application/json
Ejemplos
Go
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
}
PHP
<?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;
}
?>
Javascript
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);
});
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/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;
}
}
Python
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)
Last updated