Registrar Suscripción
Permite registrar la información para generar una suscripción junto a la información del cliente
Método: POST
Producción: https://api.payvalida.com/v4/subscriptions
curl --location --request POST 'https://api-test.payvalida.com/v4/subscriptions' \
--header 'Content-Type: application/json' \
--data-raw '{
"merchant":"kuanto",
"plan_id":"50e25c83-12ba-442f-adf8-6d410b376045",
"checksum":"d171f0254271b731d06b91ad97bb0ec284e5997c997597cc8068fc688cb94f6b7dbe6295531e01b52c67cbeb2eddfcfabe29ca12323f118d77239001ed411869",
"start_date":"22/11/2024",
"customer":{
"first_name":"user-name",
"last_name":"last-name",
"user_di":"999999999",
"type_di":"CC",
"cellphone":"+57112321131331",
"email":"user@example.com"
}
}'
curl --location --request POST 'https://api-test.payvalida.com/v4/subscriptions' \
--header 'Content-Type: application/json' \
--data-raw '{
"merchant": "test",
"plan_id": "cb2aef2d-03b1-47eb-9ca3-1179a5f64127",
"checksum": "05eb0782e16369b3d1738b907c887c0ae665b386c0180eed803a1b6cd1a0ca172ab64018c6bcfd2dfb4c52149cdcf2ad7af4868a8708a6fb28efc58ec3cc047e",
"customer": {
"first_name": "john",
"last_name": "doe",
"user_di": "888888888",
"type_di": "CC",
"cellphone": "+57300222222",
"email": "johndoe@test.com"
},
"credit_card_data": {
"card_number": "4111111111111111",
"cvv": 123,
"expiration_date": "12/26",
"franchise": "VISA",
"id_type": "CC",
"id": "888888888",
"holder_name": "john",
"holder_last_name": "doe",
"email": "johndoe@test.com",
"phone": "3002222222",
"ip": "1.1.1.1",
"header_user_agent": "test-user-agent",
"line1": "calle 123 # 12 - 23",
"line2": "CASA",
"line3": "CASA",
"country": "Colombia",
"city": "Medellin",
"state": "Antioquia",
"post_code": "050001"
}
}'
{
"CODE": "0000",
"DESC": "OK",
"DATA": {
"id": "b45fd212-2c26-4068-9807-2c9c6b8ac204",
"start_date": "14/06/2023",
"status": "ACTIVE",
"plan": {
"id": "50e25c83-12ba-442f-adf8-6d410b376045"
},
"customer": {
"id": "b45fd212-2c26-4068-9807-2c9c6b8ac204"
}
}
}
{
"CODE": "0000",
"DESC": "OK",
"DATA": {
"id": "c0b44586-bfef-4a58-92ca-d91d9201211d",
"status": "ACTIVE",
"token": "4106103912271111",
"plan": {
"id": "cb2aef2d-03b1-47eb-9ca3-1179a5f64127"
},
"customer": {
"id": "1eb44956-208f-41f2-b8fa-acf9d0e2b4a0"
}
}
}
Para los días que no existan en meses donde se debe realizar un pago, por ejemplo el día 31, el límite para realizar el pago de la suscripción será el último día de dicho mes.
Ejemplos
Go
package main
import (
"bytes"
"crypto/sha512"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"time"
)
type Payload struct {
Merchant string `json:"merchant"`
PlanID string `json:"plan_id"`
Checksum string `json:"checksum"`
StartDate string `json:"start_date"`
Customer struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
UserDI string `json:"user_di"`
TypeDI string `json:"type_di"`
Cellphone string `json:"cellphone"`
Email string `json:"email"`
} `json:"customer"`
}
func main() {
url := "https://api-test.payvalida.com/v4/subscriptions"
// Prepare the request payload
payload := Payload{
Merchant: "kuanto",
PlanID: "50e25c83-12ba-442f-adf8-6d410b376045",
Checksum: "d171f0254271b731d06b91ad97bb0ec284e5997c997597cc8068fc688cb94f6b7dbe6295531e01b52c67cbeb2eddfcfabe29ca12323f118d77239001ed411869",
StartDate: "12/12/2024"
Customer: struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
UserDI string `json:"user_di"`
TypeDI string `json:"type_di"`
Cellphone string `json:"cellphone"`
Email string `json:"email"`
}{
FirstName: "user-name",
LastName: "last-name",
UserDI: "999999999",
TypeDI: "CC",
Cellphone: "+57112321131331",
Email: "user@example.com",
},
}
// Create the checksum
data := payload.Merchant + strconv. + payload.PlanID + "FIXED_HASH"
checksum := calculateSHA512(data)
// Update the checksum value in the payload
payload.Checksum = checksum
// Convert the payload to JSON
requestBody, err := json.Marshal(payload)
if err != nil {
fmt.Println("Error marshaling request payload:", err)
return
}
// Send the POST request
resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody))
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
// Read the response body
responseBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
// Print the response body
fmt.Println("Response Body:", string(responseBody))
}
func calculateSHA512(data string) string {
hash := sha512.Sum512([]byte(data))
return hex.EncodeToString(hash[:])
}
PHP
<?php
$url = 'https://api-test.payvalida.com/v4/subscriptions';
// Prepare the request payload
$payload = array(
"merchant" => "kuanto",
"plan_id" => "50e25c83-12ba-442f-adf8-6d410b376045",
"checksum" => "d171f0254271b731d06b91ad97bb0ec284e5997c997597cc8068fc688cb94f6b7dbe6295531e01b52c67cbeb2eddfcfabe29ca12323f118d77239001ed411869",
"start_date" => "12/12/2024",
"customer" => array(
"first_name" => "user-name",
"last_name" => "last-name",
"user_di" => "999999999",
"type_di" => "CC",
"cellphone" => "+57112321131331",
"email" => "user@example.com"
)
);
// Create the checksum
$data = $payload['merchant'] . $payload['plan_id'] . 'FIXED_HASH';
$checksum = hash('sha512', $data);
// Update the checksum value in the payload
$payload['checksum'] = $checksum;
// Convert the payload to JSON
$requestBody = json_encode($payload);
// Set the request headers
$headers = array(
'Content-Type: application/json'
);
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute the cURL request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_error($ch)) {
echo 'Error: ' . curl_error($ch);
exit;
}
// Close cURL
curl_close($ch);
// Print the response body
echo 'Response Body: ' . $response;
Javascript
const fetch = require('node-fetch');
const crypto = require('crypto');
const url = 'https://api-test.payvalida.com/v4/subscriptions';
// Prepare the request payload
const payload = {
merchant: 'kuanto',
plan_id: '50e25c83-12ba-442f-adf8-6d410b376045',
checksum: 'd171f0254271b731d06b91ad97bb0ec284e5997c997597cc8068fc688cb94f6b7dbe6295531e01b52c67cbeb2eddfcfabe29ca12323f118d77239001ed411869',
start_date: '12/12/2024',
customer: {
first_name: 'user-name',
last_name: 'last-name',
user_di: '999999999',
type_di: 'CC',
cellphone: '+57112321131331',
email: 'user@example.com',
},
};
// Create the checksum
const data = payload.merchant + payload.plan_id + 'FIXED_HASH';
const checksum = crypto.createHash('sha512').update(data).digest('hex');
// Update the checksum value in the payload
payload.checksum = checksum;
// Send the POST request
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
})
.then((response) => response.json())
.then((data) => {
console.log('Response Body:', data);
})
.catch((error) => {
console.error('Error:', 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";
// Prepare the request payload
String payload = "{\n" +
" \"merchant\":\"kuanto\",\n" +
" \"plan_id\":\"50e25c83-12ba-442f-adf8-6d410b376045\",\n" +
" \"checksum\":\"d171f0254271b731d06b91ad97bb0ec284e5997c997597cc8068fc688cb94f6b7dbe6295531e01b52c67cbeb2eddfcfabe29ca12323f118d77239001ed411869\",\n" +
" \"start_date\":\"12/12/2024\",\n" +
" \"customer\":{\n" +
" \"first_name\":\"user-name\",\n" +
" \"last_name\":\"last-name\",\n" +
" \"user_di\":\"999999999\",\n" +
" \"type_di\":\"CC\",\n" +
" \"cellphone\":\"+57112321131331\",\n" +
" \"email\":\"user@example.com\"\n" +
" }\n" +
"}";
// Create the checksum
String data = "kuanto" + "50e25c83-12ba-442f-adf8-6d410b376045" + "FIXED_HASH";
String checksum = getSHA512Checksum(data);
// Update the checksum value in the payload
payload = payload.replace("d171f0254271b731d06b91ad97bb0ec284e5997c997597cc8068fc688cb94f6b7dbe6295531e01b52c67cbeb2eddfcfabe29ca12323f118d77239001ed411869", checksum);
try {
// Create the HTTP connection
URL apiUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);
// Send the request payload
try (OutputStream outputStream = connection.getOutputStream()) {
byte[] input = payload.getBytes(StandardCharsets.UTF_8);
outputStream.write(input, 0, input.length);
}
// Get the response
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
System.out.println("Response Body: " + response.toString());
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static String getSHA512Checksum(String data) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-512");
byte[] hashBytes = digest.digest(data.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'
# Prepare the request payload
payload = {
"merchant": "kuanto",
"plan_id": "50e25c83-12ba-442f-adf8-6d410b376045",
"checksum": "d171f0254271b731d06b91ad97bb0ec284e5997c997597cc8068fc688cb94f6b7dbe6295531e01b52c67cbeb2eddfcfabe29ca12323f118d77239001ed411869",
"start_date": "12/12/2024",
"customer": {
"first_name": "user-name",
"last_name": "last-name",
"user_di": "999999999",
"type_di": "CC",
"cellphone": "+57112321131331",
"email": "user@example.com"
}
}
# Create the checksum
data = payload['merchant'] + payload['plan_id'] + 'FIXED_HASH'
checksum = hashlib.sha512(data.encode()).hexdigest()
# Update the checksum value in the payload
payload['checksum'] = checksum
# Send the POST request
response = requests.post(url, json=payload)
# Print the response body
print('Response Body:', response.json())hin
Last updated