Skip to content

Commit

Permalink
Relate payment status properties to drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
kamirr committed Sep 28, 2023
1 parent 2db22ce commit d803ecb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
6 changes: 0 additions & 6 deletions model/src/payment/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ pub struct PaymentId {
pub payment_id: String,
}

#[derive(Deserialize, Serialize)]
pub struct PaymentStatusQuery {
#[serde(default)]
network: Option<String>,
}

#[derive(Deserialize, Serialize)]
pub struct Timeout {
#[serde(default)]
Expand Down
14 changes: 12 additions & 2 deletions model/src/payment/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,33 @@ pub struct Payment {
#[serde(tag = "kind")]
pub enum PaymentStatusProperty {
InsufficientGas {
driver: String,
network: String,
#[serde(rename = "neededGasEst")]
needed_gas_est: String,
},
InsufficientToken {
driver: String,
network: String,
#[serde(rename = "neededTokenEst")]
needed_token_est: String,
},
InvalidChainId {
driver: String,
#[serde(rename = "chainId")]
chain_id: i64,
},
CantSign {
driver: String,
network: String,
address: String,
},
TxStuck {
driver: String,
network: String,
},
RpcError {
driver: String,
network: String,
},
}
Expand All @@ -58,11 +64,13 @@ mod tests {
fn status_prop_serialization() {
assert_eq!(
json!({
"driver": "erc20",
"kind": "InsufficientGas",
"network": "foo",
"neededGasEst": "bar",
}),
to_value(&PaymentStatusProperty::InsufficientGas {
driver: "erc20".into(),
network: "foo".into(),
needed_gas_est: "bar".into()
})
Expand All @@ -74,12 +82,14 @@ mod tests {
fn status_prop_deserialization() {
assert_eq!(
PaymentStatusProperty::TxStuck {
driver: "erc20".into(),
network: "baz".into(),
},
from_str(
r#"{
"kind": "TxStuck",
"network": "baz"
"driver": "erc20",
"kind": "TxStuck",
"network": "baz"
}"#
)
.unwrap()
Expand Down
21 changes: 6 additions & 15 deletions specs/payment-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@ paths:
problems like missing funds or misconfigured max fee per gas on a per-chain
(network) basis.
parameters:
- $ref: '#components/parameters/paymentStatusQuery'
- $ref: 'common.yaml#/parameters/network'
- $ref: 'common.yaml#/parameters/driver'
responses:
200:
$ref: '#/components/responses/PaymentStatus'
Expand Down Expand Up @@ -776,13 +777,6 @@ components:
schema:
type: string

paymentStatusQuery:
name: paymentStatusQuery
required: true
in: path
schema:
$ref: '#/components/schemas/PaymentStatusQuery'

allocationIds:
name: allocationIds
required: true
Expand Down Expand Up @@ -1280,13 +1274,6 @@ components:
- activityPayments
- details

PaymentStatusQuery:
description: Filter for driver status properties
type: object
properties:
network:
type: string

PaymentStatusProperty:
type: object
description: Individual actionable property of the payment driver status
Expand Down Expand Up @@ -1314,6 +1301,9 @@ components:
- CantSign
- TxStuck
- RpcError
driver:
description: Payment driver to which this status property is applicable
type: string
network:
description: >
Indicates which chain the problem occurs on. No statuses other than
Expand Down Expand Up @@ -1348,6 +1338,7 @@ components:
type: integer
required:
- kind
- driver

AgreementPayment:
description: >
Expand Down
3 changes: 3 additions & 0 deletions src/payment/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,14 @@ impl PaymentApi {

pub async fn payment_status(
&self,
driver: Option<String>,
network: Option<String>,
) -> Result<Vec<PaymentStatusProperty>> {
let url = url_format!(
"payments/status/",
#[query]
driver,
#[query]
network
);

Expand Down

0 comments on commit d803ecb

Please sign in to comment.