Skip to content

Commit

Permalink
feat: [MAPS-1487] Add missing references to Merchant Account Payment …
Browse files Browse the repository at this point in the history
…and External Payment (#84)

* Added missing references to MA payment and to external payment

* External payment's remitter fields are all required.

* Bumped version

* Settled doesn't not exists for payouts, it's Executed
  • Loading branch information
tl-marco-tormento authored Nov 28, 2024
1 parent 01cc479 commit 5cf7b67
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "truelayer-rust"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

[dependencies]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ let res = tl
beneficiary: Beneficiary::MerchantAccount {
merchant_account_id: "some-merchant-account-id".to_string(),
account_holder_name: None,
reference: None,
statement_reference: None,
},
},
user: User {
Expand Down
2 changes: 2 additions & 0 deletions examples/create_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ async fn run() -> anyhow::Result<()> {
beneficiary: Beneficiary::MerchantAccount {
merchant_account_id: merchant_account.id,
account_holder_name: None,
reference: None,
statement_reference: None,
},
},
user: CreatePaymentUserRequest::NewUser {
Expand Down
20 changes: 11 additions & 9 deletions src/apis/merchant_accounts/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ mod tests {
SweepingFrequency, TransactionPayinStatus, TransactionPayoutContextCode,
TransactionPayoutStatus, TransactionType,
},
payments::{AccountIdentifier, Currency, Remitter},
payments::{AccountIdentifier, Currency, ExternalPaymentRemitter},
payouts::PayoutBeneficiary,
},
authenticator::Authenticator,
Expand Down Expand Up @@ -745,7 +745,8 @@ mod tests {
"sort_code": "sort-code",
"account_number": "account-number"
},
"account_holder_name": "Mr. Holder"
"account_holder_name": "Mr. Holder",
"reference": "ext-payment-ref"
}
},
{
Expand Down Expand Up @@ -773,9 +774,9 @@ mod tests {
"currency": "GBP",
"amount_in_minor": 100,
"type": "payout",
"status": "settled",
"status": "executed",
"created_at": &now,
"settled_at": &now,
"executed_at": &now,
"beneficiary": {
"type": "payment_source",
"user_id": "payout-user-id",
Expand Down Expand Up @@ -832,12 +833,13 @@ mod tests {
r#type: TransactionType::ExternalPayment {
status: TransactionPayinStatus::Settled,
settled_at: now,
remitter: Remitter {
account_holder_name: Some("Mr. Holder".into()),
account_identifier: Some(AccountIdentifier::SortCodeAccountNumber {
remitter: ExternalPaymentRemitter {
account_holder_name: "Mr. Holder".into(),
account_identifier: AccountIdentifier::SortCodeAccountNumber {
sort_code: "sort-code".to_string(),
account_number: "account-number".to_string()
})
},
reference: "ext-payment-ref".to_string()
}
}
},
Expand Down Expand Up @@ -865,7 +867,7 @@ mod tests {
currency: Currency::Gbp,
amount_in_minor: 100,
r#type: TransactionType::Payout {
status: TransactionPayoutStatus::Settled { settled_at: now },
status: TransactionPayoutStatus::Executed { executed_at: now },
created_at: now,
beneficiary: PayoutBeneficiary::PaymentSource {
user_id: "payout-user-id".to_string(),
Expand Down
6 changes: 3 additions & 3 deletions src/apis/merchant_accounts/model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::apis::{
payments::{AccountIdentifier, Currency, PaymentSource, Remitter},
payments::{AccountIdentifier, Currency, ExternalPaymentRemitter, PaymentSource},
payouts::PayoutBeneficiary,
};
use chrono::{DateTime, SecondsFormat, Utc};
Expand Down Expand Up @@ -80,7 +80,7 @@ pub enum TransactionType {
ExternalPayment {
status: TransactionPayinStatus,
settled_at: DateTime<Utc>,
remitter: Remitter,
remitter: ExternalPaymentRemitter,
},
Payout {
#[serde(flatten)]
Expand All @@ -102,7 +102,7 @@ pub enum TransactionPayinStatus {
#[serde(tag = "status", rename_all = "snake_case")]
pub enum TransactionPayoutStatus {
Pending,
Settled { settled_at: DateTime<Utc> },
Executed { executed_at: DateTime<Utc> },
}

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
Expand Down
8 changes: 6 additions & 2 deletions src/apis/payments/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ mod tests {
},
"beneficiary": {
"type": "merchant_account",
"merchant_account_id": "merchant-account-id"
"merchant_account_id": "merchant-account-id",
},
},
"user": {
Expand Down Expand Up @@ -509,6 +509,8 @@ mod tests {
beneficiary: Beneficiary::MerchantAccount {
merchant_account_id: "merchant-account-id".to_string(),
account_holder_name: None,
reference: None,
statement_reference: None,
},
},
user: CreatePaymentUserRequest::ExistingUser {
Expand Down Expand Up @@ -897,7 +899,9 @@ mod tests {
},
beneficiary: Beneficiary::MerchantAccount {
merchant_account_id: "merchant-account-id".to_string(),
account_holder_name: None
account_holder_name: None,
reference: None,
statement_reference: None
}
}
);
Expand Down
9 changes: 9 additions & 0 deletions src/apis/payments/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ pub enum Beneficiary {
MerchantAccount {
merchant_account_id: String,
account_holder_name: Option<String>,
reference: Option<String>,
statement_reference: Option<String>,
},
ExternalAccount {
account_holder_name: String,
Expand Down Expand Up @@ -311,6 +313,13 @@ pub struct Remitter {
pub account_identifier: Option<AccountIdentifier>,
}

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct ExternalPaymentRemitter {
pub account_holder_name: String,
pub account_identifier: AccountIdentifier,
pub reference: String,
}

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct ProviderFilter {
pub countries: Option<Vec<CountryCode>>,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
//! beneficiary: Beneficiary::MerchantAccount {
//! merchant_account_id: "some-merchant-account-id".to_string(),
//! account_holder_name: None,
//! reference: None,
//! statement_reference: None,
//! },
//! },
//! user: CreatePaymentUserRequest::NewUser {
Expand Down
2 changes: 2 additions & 0 deletions tests/integration_tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub async fn create_closed_loop_payment(
beneficiary: Beneficiary::MerchantAccount {
merchant_account_id: ctx.merchant_account_gbp_id.clone(),
account_holder_name: None,
reference: None,
statement_reference: None,
},
},
user: CreatePaymentUserRequest::NewUser {
Expand Down
4 changes: 4 additions & 0 deletions tests/integration_tests/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ async fn hpp_link_returns_200() {
beneficiary: Beneficiary::MerchantAccount {
merchant_account_id: ctx.merchant_account_gbp_id.clone(),
account_holder_name: None,
reference: None,
statement_reference: None,
},
},
user: CreatePaymentUserRequest::NewUser {
Expand Down Expand Up @@ -193,6 +195,8 @@ impl CreatePaymentScenario {
ScenarioBeneficiary::ClosedLoop => Beneficiary::MerchantAccount {
merchant_account_id: ctx.merchant_account_gbp_id.clone(),
account_holder_name: None,
reference: Some("Reference".to_string()),
statement_reference: Some("StReference".to_string()),
},
ScenarioBeneficiary::OpenLoop {
ref account_identifier,
Expand Down

0 comments on commit 5cf7b67

Please sign in to comment.