Ejemplos de uso

CURL

curl --location --request POST 'https://checkout.prod.ua.la/1/checkout' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer [[accessToken]]' \
--data-raw '{
"amount":"10.90",
"description": "Venta",
"userName": "[[userName]]",
"callback_fail": "[[url_fail]]",
"callback_success": "[[url_success]]"
}'

Python

#!/usr/bin/env/python
# -*- coding: utf-8 -*-
import json
try:
import requests
except ImportError:
print('[!] Please install the requests library')
print('[!] Example: pip install requests')
exit(1)
CHECKOUT_URL = 'https://checkout.prod.ua.la'
PAYMENT_URL = f'{CHECKOUT_URL}/1/checkout'
class Checkout:
def __init__(self, amount: str, description: str, user_name: str, callback_fail: str, callback_success: str):
self.amount = amount
self.description = description
self.userName = user_name
self.callback_fail = callback_fail
self.callback_success = callback_success
def to_dict(self) -> dict:
return vars(self)
def to_json(self) -> str:
return json.dumps(self.to_dict())
def checkout(self, access_token: str):
try:
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': f'Bearer {access_token}'
}
session = requests.Session()
response = session.post(
PAYMENT_URL,
data=self.to_json(),
headers=headers,
)
return response.json()
except requests.exceptions.RequestException as e:
raise e('[!] Checkout error')
exit(1)
if __name__ == '__main__':
checkout = Checkout(
amount='10.90',
description='Venta',
user_name='USER_NAME',
callback_fail='URL_FAIL',
callback_success='URL_SUCCESS'
)
token = 'ACCESS_TOKEN'
print(checkout.checkout(token))

Go

package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
const checkoutUrl = "https://checkout.prod.ua.la"
var paymentUrl = fmt.Sprintf("%s/1/checkout", checkoutUrl)
type (
Checkout struct {
Amount string `json:"amount"`
Description string `json:"description"`
UserName string `json:"userName"`
CallbackFail string `json:"callback_fail"`
CallbackSuccess string `json:"callback_success"`
}
Links struct {
CheckoutLink string `json:"checkout"`
Success string `json:"success"`
Failed string `json:"failed"`
}
Response struct {
ID string `json:"id"`
Type string `json:"type"`
UUID string `json:"uuid"`
OrderNumber string `json:"orderNumber"`
Currency string `json:"currency"`
Amount int `json:"amount"`
Status string `json:"status"`
Links Links `json:"links"`
}
Process interface {
Pay(token string) (Response, error)
}
)
func (checkout *Checkout) toJson() ([]byte, error) {
return json.Marshal(checkout)
}
func (checkout *Checkout) Pay(token string) (Response, error) {
var response Response
access_token := fmt.Sprintf("Bearer %s", token)
data, err := checkout.toJson()
if err != nil {
return response, err
}
request, err := http.NewRequest("POST", paymentUrl, bytes.NewBuffer(data))
if err != nil {
return response, err
}
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Authorization", access_token)
cli := &http.Client{}
resp, err := cli.Do(request)
if err != nil {
return response, err
}
defer resp.Body.Close()
if err = json.NewDecoder(resp.Body).Decode(&response); err != nil {
return response, err
}
return response, err
}
func main() {
checkout := Checkout{
Amount: "10.90",
Description: "Venta",
UserName: "USER_NAME",
CallbackFail: "URL_FAIL",
CallbackSuccess: "URL_SUCCESS",
}
token := "ACCESS_TOKEN"
response, err := checkout.Pay(token)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(response)
}
}