Skip to content

Commit

Permalink
Merge pull request NoxPay#2 from GRhama/init_v2
Browse files Browse the repository at this point in the history
Init v2
  • Loading branch information
trumae authored May 3, 2023
2 parents 3e5e3b4 + 3fc7a31 commit c6e238a
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# API documents
- [API V1](apiv1.org)
- [API V2](apiv2.org)
File renamed without changes.
247 changes: 247 additions & 0 deletions apiv2.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
#+title: API V2
#+author: Vinicius Valente Maciel, Cesar Gimenes
#+EMAIL: [email protected]
#+DESCRIPTION: API Gateway V2
#+KEYWORDS: gateway,API,test,v2
#+LANGUAGE: pt-BR
#+latex_class: article
#+latex_class_options: [a4paper,10pt,final]
#+LATEX_HEADER: \usepackage{subcaption}

#+LATEX_HEADER: \usepackage[table]{xcolor}
#+LATEX_HEADER: \usepackage[margin=0.9in,bmargin=1.0in,tmargin=1.0in]{geometry}
#+LATEX_HEADER: \usepackage{amsmath}
#+LATEX_HEADER: \usepackage{bookman}
#+LaTeX_HEADER: \newcommand{\point}[1]{\noindent \textbf{#1}}
#+LaTeX_HEADER: \usepackage{hyperref}
#+LaTeX_HEADER: \parindent = 0em
#+LaTeX_HEADER: \setlength\parskip{.5\baselineskip}
#+LaTeX_HEADER: \usepackage[latin1]{inputenc}
#+OPTIONS: H:3 num:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t ^:nil _:nil
#+OPTIONS: H:3 num:3
#+STARTUP: showall
#+STARTUP: align
#+LaTeX_HEADER: \usepackage[latin1]{inputenc}


* Introducao

The aim of this document is show how a developer can use the Nox
gateway api v2 in testnet. To use this system you must generate
an API key and have an merchant registration. *This document is
targeted towards Nox QA group*.

* API V2

** Getting an APIKEY and a merchant registration

To get an APIKEY and a merchant resgistration, you must get in
contact with Nox, so we can provide them to you.

** Setting the URL

In the testing scripts, to set the URL that will be used, you must
run the config.sh file. All other .sh files available already
run this script.

#+caption: config.sh content
#+begin_src bash :results raw
export URL=https://testnetapigateway.herokuapp.com
export APIKEY=<apikey> #substitua aqui sua apikey
#+end_src

** Checking APIKEY

To check your APIKEY, you must run the test-auth.sh file. If the .sh
runs properly, the return will be your data. *This endpoint onlys
works in the testnet*.

#+begin_src bash :results raw
source config.sh
curl --header 'api-key: ${APIKEY}' ${URL}/test-auth
echo
#+end_src

Example of the output:
#+begin_example
{"ID":1,"MerchantID":1,"Name":"NoxTrading","Hash":"-",
"CreatedAt":"2022-08-23T16:48:37Z"}
#+end_example

** Getting account data

To get your account's data, you must run the getAccount.sh file. If the .sh runs properly, the return will be the merchant's name and balance. You must have your APIKEY to run this script.

#+begin_src bash :results raw
source config.sh
custid=`uuid`
curl --header 'api-key: ${APIKEY}' ${URL}/api/account
echo
#+end_src

Example of the output:
#+begin_example
{"name":"NoxPay","balance":389.6}
#+end_example

*** Payments

**** Creating a new payment - CASH IN

To create a new payment, you must run the createPayment.sh file.
If the .sh runs properly, a new payment will be created.
The .sh also returns the payments's data.

#+begin_src bash :results raw
source config.sh

echo "Creating payment"
payment="
{
\"method\": \"PIX\",
\"code\": \"123333\",
\"amount\": 1005.00
}
"
echo ${payment} | curl \
--header 'Content-Type: application/json' \
--header 'api-key: ${APIKEY}' \
${URL}/api/payment -d @-
echo
#+end_src

Example of the output:
#+begin_example
Creating payment
{"method":"PIX",
"code":"123333",
"amount": 1005.00,
"qrcode":"https://noxbitcoin.com.br/logo-nox.svg?id=2893746",
"qrcodebase64":"aaaaabbbbbbb==",
"copypaste": "<string copy paste pagamento>",
"txid":"7132668f-9916-4bc9-9c50-89af03169e1f",
"Status":"WAITING_PAYMENT"}
#+end_example

**** Get Payment's info

To get the payment's data info you must use
the /${URL}/api/payment/{txid}/, where *txid* is
returned from the payment creation.

To simulate a payment, you must use
the /${URL}/api/payment/pay/${txid}/.
This feature only works in the testnet instance of the system.

#+begin_src bash :results raw
source config.sh

echo "Creating payment"
payment="
{
\"method\": \"PIX\",
\"code\": \"123333\",
\"amount\": 1005.00
}
"
txid=`echo ${payment} | curl -s \
--header 'Content-Type: application/json' \
--header 'api-key: ${APIKEY}' \
${URL}/api/payment -d @- | jq -r .txid`
echo ${txid}

curl --header 'api-key: ${APIKEY}' ${URL}/api/account
echo
curl -s --header 'api-key: ${APIKEY}' \
${URL}/api/payment/${txid}
echo
curl -s --header 'api-key: ${APIKEY}' \
${URL}/api/payment/pay/${txid}
echo
curl -s --header 'api-key: ${APIKEY}' \
${URL}/api/payment/${txid}
echo
curl --header 'api-key: ${APIKEY}' \
${URL}/api/account
echo
#+end_src

Example of the output:
#+begin_example
Creating payment
{"name":"NoxPay","balance":389.6}
{"Method":"PIX","Status":"WAITING_PAYMENT",
"Code":"123333","TxID":"789c7d41-1cab-4410-9699-79979e4ece91",
"Amount":150100,"end2end": "","receipt": ""}
{"Method":"PIX","Status":"PAY",
"Code":"123333","TxID":"789c7d41-1cab-4410-9699-79979e4ece91",
"Amount":150100}
{"Method":"PIX","Status":"PAY",
"Code":"123333","TxID":"789c7d41-1cab-4410-9699-79979e4ece91",
"Amount":150100, "end2end": "2134234","receipt": "http://example.com"}
{"name":"NoxTrading","balance":300200}
#+end_example

**** Creating a new payment - CASH OUT

To create a new cash out payment, you must run the code.
If the it runs properly, a new payment cash out will be created.
The return is the payments's data.

O campo *type* especifica o tipo da informacao de pagamento do destinatario.
Podendo ser uma chave pix convencional (PIXKEY) ou os dados de uma conta
bancaria (ACCOUNT). No primeiro caso (PIXKEY) o campo "pixkey" passa a ser
obrigatorio. No segundo caso (ACCOUNT) o campo "bank_account" passa a ser
obrigatorio.

#+begin_src bash :results raw
source config.sh

echo "========> Creating payment out"
paymentout="
{
\"method\": \"PIXOUT\",
\"type\": \"PIXKEY\" //or ACCOUNT
\"code\": \"123\",
\"pixkey\": \"key\": \"[email protected]\",
\"bank_account\": {
\"name\": \"Fulano de souza\",
\"cpf_cnpj\": \"12863843893\",
\"bank_code\": \"001\",
\"agency\": \"3333\",
\"account\": \"12345\",
\"account_digit\": \"1\",
\"account_type\": \"CONTA_CORRENTE\"
}
\"amount\": 1000.00
}
"

txoutid=`echo ${paymentout} | curl -s \
--header 'Content-Type: application/json' \
--header 'api-key: 12345678' \
${URL}/api/payment -d @- | jq -r .txid`
echo ${txoutid}

curl --header 'api-key: 12345678' ${URL}/api/account
echo
curl -s --header 'api-key: 12345678' ${URL}/api/payment/${txoutid}
echo "========> Pagando"
curl -s --header 'api-key: 12345678' ${URL}/api/payment/pay/${txoutid}
echo
curl --header 'api-key: 12345678' ${URL}/api/account
echo
#+end_src

Example of the output:
#+begin_example
========> Creating payment out
2ed3f4d5-3365-47b6-bf24-83ee380a77c6
{"name":"NoxTrading","balance":300}
{"Method":"PIXOUT","Status":"WAITING_PAYMENT","Code":"123",
"TxID":"2ed3f4d5-3365-47b6-bf24-83ee380a77c6","Amount":250}
========> Pagando
{"Method":"PIXOUT","Status":"PAY","Code":"123",
"TxID":"2ed3f4d5-3365-47b6-bf24-83ee380a77c6","Amount":250}
{"name":"NoxTrading","balance":50}
#+end_example

0 comments on commit c6e238a

Please sign in to comment.