APISamples_Payments - POPRecarga/PartnerAPI GitHub Wiki

#Payment Only authenticated user can do this.

Method Resource Notes
POST /payments Creates a new payment in the system.
GET /payments/{transactionId} Retrieve payment transaction details.
GET /payments/{transactionId}/token/ Resend a new token for a specified transaction.
PUT /payments/{transactionId}/token/{token} Authorize the specified transaction using specified token.
PUT /payments/{transactionId}/execute Execute the specified transaction.
PUT /payments/{transactionId}/cancel Cancel not executed transaction. Just pending, authorized and inactive transactions can be cancelled.

Requests

Valid POST request at /payments:

POST /payments HTTP/1.1
Host: api.sandbox.inpdv.com.br
Content-Type: application/json; charset=utf-8
Authorization: Bearer oHPBScnPNxJYRe7f9jtvHsSk627_CGzkgGi-f…
Content-Length: 187

{
    "brandId": 1,
    "identifier": "+5511XXXXXXXXX",
    "transaction": {
        "amount": 1.99,
        "currencyCode": "BRL",
        "description": "Product X",
        "referralCode": "a48s4d87g8a9d5v8h4k4az48f4"  
    }
}

Valid GET request at /payments/{transaction}:

GET /payments/96af9850-bdbb-42c0-95c3-cb6a5a3178ae HTTP/1.1
Host: api.sandbox.inpdv.com.br
Content-Type: application/json; charset=utf-8
Authorization: Bearer oHPBScnPNxJYRe7f9jtvHsSk627_3ap7ISSw…


Valid GET request at /payments/{transaction}/token:

GET /payments/96af9850-bdbb-42c0-95c3-cb6a5a3178ae/token HTTP/1.1
Host: api.sandbox.inpdv.com.br
Content-Type: application/json; charset=utf-8
Authorization: Bearer oHPBScnPNxJYRe7f9jtvHsSk627_CGzkgGi-fscDRE…


Valid PUT request at /payments/{transaction}/token/{token}:

GET /payments/96af9850-bdbb-42c0-95c3-cb6a5a3178ae/token/648741 HTTP/1.1
Host: api.sandbox.inpdv.com.br
Content-Type: application/json; charset=utf-8
Authorization: Bearer oHPBScnPNxJYRe7f9jtvHsSk627_CGzkgGi-fscDRE…


Valid PUT request at /payments/{transaction}/execute:

PUT /payments/0972741f-7aa1-47b8-a1aa-8774c7031c1c/execute HTTP/1.1
Host: api.sandbox.inpdv.com.br
Content-Type: application/json; charset=utf-8
Authorization: Bearer oHPBScnPNxJYRe7f9jtvHsSk627_CGzkgGi-fscDRE…


Valid PUT request at /payments/{transaction}/cancel:

PUT /payments/a48bfd6b-c671-4354-9cb9-49bcf196faf9/cancel HTTP/1.1
Host: api.sandbox.inpdv.com.br
Content-Type: application/json; charset=utf-8
Authorization: Bearer oHPBScnPNxJYRe7f9jtvHsSk627_CGzkgGi-fRWRRjH8v…


Responses

Success POST response from /payments:

HTTP/1.1 201 Created
Content-Length: 474

{
    "id":"4e319e3d-07f7-4181-9403-0505f01fd2cc",
    "status":"Pending",
    "amount":1.99,
    "links":
    [
        {"href":"https://inpdv-api-sandbox.net/payments/4e319e3d..."},
        {"href":"https://inpdv-api-sandbox.net/payments/4e319e3d.../cancel","rel":"Cancel","method":"Put"},
        {"href":"https://inpdv-api-sandbox.net/payments/4e319e3d.../token/"tokenvalue","rel":"Approval","method":"Put"}
    ]
}

Invalid amount POST response from /payments:

HTTP/1.1 400 Bad Request
Content-Length: 148

{
    "codeDescription":"UnknownError",
    "extendedProperties":{"mS_LoggedBy":[{}]},
    "message":"The amount must be greater than 0\r\nParameter name: amount"
}

OBS: any invalid paramter will come with the same 400 error, but with different messages


Sucess GET response at /payments/{transaction}:

HTTP/1.1 200 OK
Content-Length: 92

{
    "id":"96af9850-bdbb-42c0-95c3-cb6a5a3178ae",
    "status":"Authorized",
    "amount":1.99,
    "links":[]
}

Sucess GET response at /payments/{transaction} when the transaction have one or more chargebacks:

HTTP/1.1 200 OK
Content-Length: 92

{
    "id":"96af9850-bdbb-42c0-95c3-cb6a5a3178ae",
    "status":"Finalized",
    "amount":20.00,
    "links":[],
    "chargebacks":
    [
        {"href":"http://localhost:58043/payments/9a21d151-e183-11e5-be9a-5cf9ddee0305"},
        {"href":"http://localhost:58043/payments/eccffc91-e183-11e5-be9a-5cf9ddee0305"},
        {"href":"http://localhost:58043/payments/58203abc-e184-11e5-be9a-5cf9ddee0305"}
    ]
}

The amount is the original transaction amount, and the chargebacks are links to this transaction chargebacks


GET response at /payments/{transaction} using wrong transaction:

HTTP/1.1 404 Not Found
Content-Length: 177

{
    "code":1,"codeDescription":"NotFound",
    "extendedProperties":
    {
        "mS_LoggedBy":[{}]
    },
    "message":"The Transaction identified by '96af9850-bdbb-42c0-95c3-cb6a5a31a7ae' was not found."
}

Success PUT response from /payments/{transaction}/token:

HTTP/1.1 200 OK
Content-Length: 4

true

Success PUT response from /payments/{transaction}/token/{token}:

HTTP/1.1 200 OK
Content-Length: 458

{
    "id":"96af9850-bdbb-42c0-95c3-cb6a5a3178ae",
    "status":"Authorized",
    "amount":1.99,
    "links":
    [
        {"href":"https://inpdv-api-hmg.azurewebsites.net/payments/96af9850-bdbb-42c0-95c3-cb6a5a3178ae"},
        {"href":"https://inpdv-api-hmg.azurewebsites.net/payments/96af9850-bdbb-42c0-95c3-cb6a5a3178ae/execute","rel":"Execute","method":"Put"},
        {"href":"https://inpdv-api-hmg.azurewebsites.net/payments/96af9850-bdbb-42c0-95c3-cb6a5a3178ae/cancel","rel":"Cancel","method":"Put"}
    ]
}

Expired Transaction PUT response from /payments/{transaction}/token/{token}:

HTTP/1.1 400 Bad Request
Content-Length: 154

{
    "code":7,
    "codeDescription":"ExpiredTransactionToken",
    "extendedProperties":{"mS_LoggedBy":[{}]},
    "message":"The transaction token has expired by timeout."
}

Executed/canceled Transaction PUT response from /payments/{transaction}/token/{token}:

HTTP/1.1 400 Bad Request
Content-Length: 156

{
    "code":9,
    "codeDescription":"AlreadyExecutedTransaction",
    "extendedProperties":{"mS_LoggedBy":[{}]},
    "message":"The transaction already has its final state."
}

Wrong token PUT response from /payments/{transaction}/token/{token}:

HTTP/1.1 400 Bad Request
Content-Length: 170

{
    "code":8,
    "codeDescription":"InvalidTransactionToken",
    "extendedProperties":{"failCount":1,"failLimit":3,"mS_LoggedBy":[{}]},
    "message":"The transaction token is invalid."
}

If the user fail 3 times his account is locked and must unlock it before making any other purchase.


Already used token response from /payments/{transaction}/token/{token}:

HTTP/1.1 400 Bad Request
Content-Length: 121

{
    "code":18,
    "codeDescription":"TokenAlreadyUsed",
    "extendedProperties":{"mS_LoggedBy":[{}]},
    "message":"token already used"
}

For security reasons the token is a TOTP. If the time-valid token was already used the user must wait until a new token can be generated.


Success PUT response from /payments/{transaction}/execute:

HTTP/1.1 200 OK
Content-Length: 186

{
    "id":"0972741f-7aa1-47b8-a1aa-8774c7031c1c",
    "status":"Finished",
    "amount":1.99,
    "links":[{"href":"https://inpdv-api-hmg.azurewebsites.net/payments/0972741f-7aa1-47b8-a1aa-8774c7031c1c"}]
}

PUT response from /payments/{transaction}/execute when the transaction was not Authorized:

HTTP/1.1 400 Bad Request
Content-Length: 145

{
    "code":5,
    "codeDescription":"NotAuthorizedTransaction",
    "extendedProperties":{"mS_LoggedBy":[{}]},"message":"The transaction must be authorized."
}

Success PUT response from /payments/{transaction}/cancel:

HTTP/1.1 200 OK
Content-Length: 187

{
    "id":"a48bfd6b-c671-4354-9cb9-49bcf196faf9",
    "status":"Cancelled",
    "amount":1.99,
    "links":[{"href":"https://inpdv-api-hmg.azurewebsites.net/payments/a48bfd6b-c671-4354-9cb9-49bcf196faf9"}]
}


⚠️ **GitHub.com Fallback** ⚠️