Skip to content

Payment Managment

Przemysław Rekucki edited this page May 14, 2024 · 9 revisions

Payment Managment

Introduction

Often an application allocates a resource and then is stopped or killed in a way that prevents it from informing the server that the resources are free. In particular, this applies to token allocation.

The purpose of the document is to add a specification that allows you to complete the task correctly even if rquestor crashes.

Sollution

Allocation timeout

#[serde(rename_all = "camelCase")]
pub struct NewAllocation {
    pub address: Option<String>,
    pub payment_platform: Option<String>,
    pub total_amount: BigDecimal,
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub timeout: Option<DateTime<Utc>>,
    pub make_deposit: bool,

    #[serde(default)]
    #[serde_as(as = "Option<serde_with::DurationSeconds<i64>>")]
    pub extend_timeout : Option<Duration>
}

New field extendTimeout specifies how much to extend the timeout when a given allocation is used.

Usage scenario

  1. Creataing allocation
POST /payment-api/v1/allocations
content-type: application/json

{
   "paymentPlatform": "erc20-polygon-glm",
   "totalAmount": 1.0,
   "timeout": "2023-08-28T15:16:31.858Z",
   "makeDeposit": false,
   "extendTimeout": 3600   
}

Creates allocation that expires at 2023-08-28 15:16:31.858 UTC but if we accept debit note or invoice with this allocation it is extented by 1 hour from last accept action.

  1. Extending allocation time & amount
PUT /payment-api/v1/allocations/7fe95de8-7163-4c37-a146-e111e07a0936
content-type: application/json

{
   "totalAmount": "1.5",
   "timeout": "2023-08-28T17:16:31.858Z",
}

Auto accepting invoice

POST /payment-api/v1/debitNotes/1aaff21c-466e-11ee-af1b-074a966e5f97/accept
content-type: application/json

{
  "totalAmountAccepted": "1.5",
  "autoAcceptTo": "1.57",
  "allocationId": "7fe95de8-7163-4c37-a146-e111e07a0936"
}

if requestor does not accept invoice in 15 minutes. and final invoice is for less then 1.57 GLM it will be auto accepted. it will be auto rejected otherwise.