En este segmento encontrarás cómo integrar dentro de tu modelo de negocio la opción para cargos periódicos como membresias y suscripciones.
Debes crear la lógica de calendario en tu sistema, así como los siguientes pasos para el cargo periódico a las tarjetas.
Pasos
1. Crear un customer_id.
2. Tokenizar la tarjeta con nuestras Librerías de Tokenización.
3. Asociar la tarjeta al cus_id creado en el paso 1.
4. Realizar el cargo al nuevo token.
1. Crear un customer_id.
POST Customer Create
https://sandbox-api.srpago.com/v1/customer
headers
body
{"name":"here the name2","email":"[email protected]","metadata":{"algo":"value"}}
Example Request
curl --location --request POST "https://sandbox-api.srpago.com/v1/customer" \ --header "Content-Type: application/json" \ --header "Authorization: Basic " \ --data "{\"name\":\"here the name2\",\"email\":\"[email protected]\",\"metadata\":{\"algo\":\"value\"}}"
var settings = { "url": "https://sandbox-api.srpago.com/v1/customer", "method": "POST", "timeout": 0, "headers": { "Content-Type": "application/json" }, "data": "{\"name\":\"here the name2\",\"email\":\"[email protected]\",\"metadata\":{\"algo\":\"value\"}}", }; $.ajax(settings).done(function (response) { console.log(response); });
require "uri" require "net/http" url = URI("https://sandbox-api.srpago.com/v1/customer") http = Net::HTTP.new(url.host, url.port) request = Net::HTTP::Post.new(url) request["Content-Type"] = "application/json" request["Authorization"] = "Basic " request.body = "{\"name\":\"here the name2\",\"email\":\"[email protected]\",\"metadata\":{\"algo\":\"value\"}}" response = http.request(request) puts response.read_body
import requests url = 'https://sandbox-api.srpago.com/v1/customer' payload = "{\"name\":\"here the name2\",\"email\":\"[email protected]\",\"metadata\":{\"algo\":\"value\"}}" headers = { 'Content-Type': 'application/json', 'Authorization': 'Basic ' } response = requests.request('POST', url, headers = headers, data = payload, allow_redirects=False, timeout=undefined, allow_redirects=false) print(response.text)
var https = require('https'); var options = { 'method': 'POST', 'hostname': 'https://sandbox-api.srpago.com', 'path': '/v1/customer', 'headers': { 'Content-Type': 'application/json', 'Authorization': 'Basic <credentials' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); var postData = "{\"name\":\"here the name2\",\"email\":\"[email protected]\",\"metadata\":{\"algo\":\"value\"}}"; req.write(postData); req.end();
package main import ( "fmt" "strings" "os" "path/filepath" "net/http" "io/ioutil" ) func main() { url := "https://sandbox-api.srpago.com/v1/customer" method := "POST" payload := strings.NewReader("{\"name\":\"here the name2\",\"email\":\"[email protected]\",\"metadata\":{\"algo\":\"value\"}}") client := &http.Client { CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, } req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) } req.Header.Add("Content-Type", "application/json") req.Header.Add("Authorization", "Basic ") res, err := client.Do(req) defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) fmt.Println(string(body)) }
Example Response
{ "success": true, "result": { "id": "cus_5f7b769b43b3e", "name": "here the name2", "email": "[email protected]", "active": 1, "date_create": "2020-10-05T14:40:11-05:00", "sources": [], "cards": [], "metadata": { "algo": "value" }, "deactivated_cards": 0 } }
2. Tokenizar tarjeta
3. Asociar tarjeta al usuario (customer_id).
Una vez hayas obtenido un token tipo tok_, el siguiente paso es asociarlo al customer_id creado en el paso 1.
En este caso utilizarás el servicio Customer Card Add
POST Customer Card Add
{{DOMAIN}}/v1/customer/cus_576c1d85baf38/cards
headers
body
{"token":"tok_9999"}
Example Request
curl --location --request POST '{{DOMAIN}}/v1/customer/cus_576c1d85baf38/cards' --header 'Content-Type: application/json' --data-raw '{"token":"tok_9999"}'
Example Request
curl --location --request POST '{{DOMAIN}}/v1/customer/cus_576c1d85baf38/cards' --header 'Content-Type: application/json' --data-raw '{"token":"tok_9999"}'
El nuevo token generado tipo crd_ te permitirá realizar cargos periódicos ya sean para membresías, suscripciones o cargos OnDemand.
Este token se quedará asociado al customer_id y será el que debes utilizar para el cobro.