This endpoint allows to create a cash in transaction via Payment Initiation with OpenFinance.
Reference Endpoint
POST /accounts/payment-initiation
Success Scenario
The request payload is composed of three inner objects: payment, transaction and webhook, as seen in this example request.
{
"payment": {
"payer": {
"taxNumber": "13600642650"
},
"value": {
"original": "10.00"
},
"redirectUrl": "https://merchantwebsite.com/success"
},
"transaction": {
"orderId": "in-410987401-001479147149841",
"orderDescription": "Test-transaction with payment initiation"
},
"webhook": {
"url": "https://postman-echo.com/post?test=1",
"customHeaderName": "Authorization",
"customHeaderValue": "eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiI2YTZjYjY2NC03NzI4LTRjM"
}
}
- The Request Fields
Field | Type | Required | Description |
---|---|---|---|
payment.payer.taxNumber | string | true | The end-user (requestor) CPF. |
payment.value.original | string | true | The effective value to be paid. |
payment.redirectUrl | string | true | The URL the end-user will be redirected to after he/she completes the transaction. |
transaction.orderId | string | false | A custom order id the integrator might want to provide for counter-check when the response arrives. |
transaction.orderDescription | string | false | A custom description the integrator might want to provide for counter-check when the response arrives. |
webhook.url | string | true | An absolute URL to recieve webhook notification events. |
webhook.customHeaderName | string | false | A custom header name for counter-check when the webhook message arrives. |
webhook.customHeaderValue | string | false | A custom header value for counter-check when the webhook message arrives. |
- Success Response (
201 - Created
)
{
"statusCode": "Done",
"data": {
"transactionId": "0a3d2b84-87ef-4c2e-aa3d-b7cfb6d76e9d",
"checkoutUrl": "https://checkout.sandbox.pagfast.com/v1/system/checkout/init/0ea70001-0f58-44a2-80ad-953633ff2cc7/0a3d2b84-87ef-4c2e-aa3d-b7cfb6d76e9d"
}
}
- The Response Fields
Field | Type | Description |
---|---|---|
transactionId | String | An Unique Identifier (UID) for the transaction. |
checkoutUrl | String | The URL where to the merchant should redirect the end-user, so that he/she can proceed with the payment. |
CPF Validation
Just like on PIX transactions, PagFast validates the CPF and denies requests for fake CPFs. While integrating, please use one of these real world CPFs for test:
13600642650, 10777438666
.
Failure Scenarios (Useful Examples)
Scenario 1: Missing required field payment.value
.
payment.value
.{
"payment": {
"payer": {
"taxNumber": "13600642650"
},
"redirectUrl": "https://merchantwebsite.com/success"
},
"transaction": {
"orderId": "in-410987401-001479147149841",
"orderDescription": "Test-transaction with payment initiation"
},
"webhook": {
"url": "https://postman-echo.com/post?test=1",
"customHeaderName": "Authorization",
"customHeaderValue": "eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiI2YTZjYjY2NC03NzI4LTRjM"
}
}
- Failure Response (
400 - Bad Request
)
{
"statusCode": "Error",
"error": {
"name": "InvalidRequestFormatError",
"message": "The request body is invalid. See error object `details` property for more info",
"details": [
{
"path": "/payment",
"code": "required",
"message": "must have required property 'value'",
"info": {
"missingProperty": "value"
}
}
]
}
}
Scenario 2: Authentication Failure
If a request include an expired or invalid authentication token, the following error will be returned.
- Failure Response (
401 Unauthorized
)
{
"statusCode": "Error",
"error": {
"name": "AuthenticationError",
"message": "The authorization token is invalid",
"details": {
"reason": "AuthenticationTokenInvalid"
}
}
}
Scenario 3: Invalid field payment.payer.taxNumber
payment.payer.taxNumber
{
"payment": {
"value": {
"original": "10.00"
},
"payer": {
"taxNumber": "33251500012"
},
"redirectUrl": "https://merchantwebsite.com/success"
},
"transaction": {
"orderId": "in-410987401-001479147149841",
"orderDescription": "Test-transaction with payment initiation"
},
"webhook": {
"url": "https://postman-echo.com/post?test=1",
"customHeaderName": "Authorization",
"customHeaderValue": "eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiI2YTZjYjY2NC03NzI4LTRjM"
}
}
- Failure Response (
409 - Conflict
)
{
"statusCode": "Error",
"error": {
"name": "OperationError",
"code": "OperationError",
"details": {
"reason": "CounterpartyTaxNumberInvalid",
"message": "TaxNumber:33251500012"
}
}
}
Malformed requests
During tests, it is possible that integrators provide some incomplete or malformed request that cause a response an error
500 - Internal Server Error
.