Main.credit-account.api - API 
Page of - last modified by David Persson on 2022/08/11 10:43 
API 

David Persson

2022/08/11 10:43
Table of Contents
ChangeLog
Glossary
Introduction
API resources overview
REST-full pattern guidance
Problems

Integrate to 
ChangeLog
Glossary
�	  
Introduction
The credit-account functions i divided in three different apis.
�	Acquiring - Functions to create reservations and transactions on an account.  
�	Onboarding   - Functions to list possible account types, onboard/create new accounts including the signing process
�	Account  - Functions to view details and interact with a specific account
API resources overview
REST-full pattern guidance
The resources follows REST-full patterns including hyper-media links, we use hyper-media and backend-for-frontend principles to impose business rules and reduce duplication of business logic. Errors uses HTTP friendly status codes as well as detailed "problem+json" responses.

Route segments
Each resource in the API corresponds to its own route. All routes are structured according to a specific standard, explained below
The below route is an example of a route towards resource3Id, to operate on this resource you must also include the ids of its parentresources in the route.

Route segment	Description	
Subdomain	which subdomain under "ledger" to call, (credit-account / credit-account-acquiring etc.)	
LedgerNumber	The ledger identifier/number at PayEx	
resource1Id	Identifier of resource1	
resource2Id	identifier of resource2, subresource to resource1	
resource3Id	identifier of resource3, subresource to resource2	
Basic resources

Requests  specific resource identifier   - f.ex. /ledger/credit-account/v1/XXX/accounts
�	HTTP GET - Returns a list of resources
�	HTTP POST - Creates a new resource
Requests  specific    - f.ex. /ledger/credit-account/v1/XXX/accounts
�	HTTP GET - Returns a specific resource
�	HTTP PUT - Updates a specific resource
�	HTTP PATCH - Partially updates a specific resource  
�	HTTP DELETE - Deletes a specific resource
Operation resources
.
Requests  specific resource identifier operates on the list
�	HTTP POST   - f.ex. /ledger/credit-account/v1/XXX/accounts/generate-summary - Generates a summary
Requests  specific resource identifier operates on a resource
�	HTTP POST   - f.ex. /ledger/credit-account/v1/XXX/accounts/1234568/initiates-termination -   Starts termination of an account
Hyper-media response
The response will include a list of operations that is possible to perform. Below is an example when a HTTP-GET Request is issued to retrieve information on an account. The response includes an "operations" property with a list of possible possible operations. The list of operations returned only contains business-rule and access-control validated operations. In the sample below the only allowed way to interact with the resource is to issue "patch" requests to modify fields. Different states as well as access permissions on the resource affect which operations are returned.

{
        "@id": "/ledger/credit-account/v1/501/accounts/1234567", //Resource identifier
        //Fields...
        "operations" : [
                {
                      "rel" : "partial-update",
                      "method" : "patch",
                      "href" : "/ledger/credit-account-onboardings/v1/501/accounts/123456"
                }
        ]
}
 As an implementing consumer of the api  should be taken into consideration rather than trying to determine possible operation based on other basic resource properties. By following this tip we: minimize duplication of business logic, simplify maintenance when business rules change, have a clear separation of concerns.
Properties used for idempotency
For operations that are idempotent, clients can make the same call multiple times while giving the same results. In other words, multiple identical requests have the same effect as making a single request.
This can be used to re-run failed requests. For requests that, for example, fail due to timeout, there is a possibility that it has been executed at PayEx. In such cases, the request can be run again without duplicates.
This is based on the same request being sent again. In some cases it is enough that certain references / identifiers are the same, in which case these are marked in the API spec  

Problems
Errors uses HTTP friendly status codes as well as detailed "problem+json" responses. All errors that can be avoided by the client is in the  ragne, all errors that must be fixed by payex is in the  range. All errors contains an instance-id, the instance-id should be provided in support questions to simplify the support process.
If an error occur or any validation failed, a "problem" response will be returned.
Below is a list of problems that can occur:

�	Token expired
�	Token invalid
�	SellerNumber does not match token
�	CompanyNumber does not match token

�	Validation: Argument required
�	Validation: Invalid value

�	Authorization declined

�	Invoice already authorized
�	Duplicate InvoiceNumber
�	Authorization is cancelled
�	Authorization already captured
�	Authorization has expired
�	Insufficient debited amount XXX

�	CompanyNumber XXX not configured
�	SellerNumber XXX not configured at PayEx
�	CompanyNumber XXX missing configuration

�	Authorization not found
Sample
Below is an example of a problem that will be returned if buyer.nationalConsumerIdentifier.value is not valid in the authorization post request.

HTTP/1.1 400 Error
Content-Type: application/problem+json

{
      "Type": "http://[DNS]/ledger/invoice-purchase/problems/validation",
      "Title": "A validation error occurred",
      "Status": 400, //Fel status code..
      "Instance": "dd07e588-70c8-4b27-95f5-020cc2968c06", 
      "Detail": "A validation error occurred. Please fix the problems mentioned in the 'problems' property below.",
      "Problems": [
                {
                      "buyer.nationalConsumerIdentifier.value": "Not a valid SE nationalConsumerIdentifier"
                }
        ]
}