Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(payments): add api locking for payments core #1898

Merged
merged 26 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
18d824c
feat(core): add api locking interface
Abhicodes-crypto Feb 23, 2023
dff1051
feat(payments): add api-locking for payments core
Abhicodes-crypto Aug 8, 2023
d2480b3
refactor: clean up
Abhicodes-crypto Aug 8, 2023
797234c
fix: cargo hack
Abhicodes-crypto Aug 10, 2023
9a1faf2
reafactor: remove code comments
Abhicodes-crypto Aug 10, 2023
9fadcb9
refactor: resolve comments
Abhicodes-crypto Aug 23, 2023
ec4d52c
refactor: rename feature to api_locking
Abhicodes-crypto Aug 23, 2023
2ebc891
temp
Abhicodes-crypto Aug 23, 2023
0ae0995
refactor: Merge commit a58cccc from main
Abhicodes-crypto Sep 12, 2023
4249620
refactor(api-locking): reduce the functions in locking and add consta…
Abhicodes-crypto Sep 13, 2023
8be8ad3
refactor: use lock function in server_wrap
Abhicodes-crypto Sep 13, 2023
6ba6caf
refactor: add locking action paramter in server_wrap
Abhicodes-crypto Sep 14, 2023
a49912e
refactor: add locking_action in server_Wrap and call lock functions i…
Abhicodes-crypto Sep 14, 2023
9b873ae
feat: add lock in payments webhooks flow
Abhicodes-crypto Sep 15, 2023
2819271
refactor: move api locking consts into settings
Abhicodes-crypto Sep 15, 2023
bbd6218
refactor: del unnecessary file
Abhicodes-crypto Sep 15, 2023
8136e31
fix: stack overflow error in update config
Abhicodes-crypto Sep 15, 2023
a8660ee
refactor: put lock env in settings
Abhicodes-crypto Sep 20, 2023
2eb2460
feat(locking): validate request_id before releasing lock
Abhicodes-crypto Sep 20, 2023
e455d69
Merge main to api-locking
Abhicodes-crypto Sep 21, 2023
e0faae9
feat(locking): add lock settings in developement.toml and add validat…
Abhicodes-crypto Sep 21, 2023
d5db2ff
feat(locking): address comments
Abhicodes-crypto Sep 22, 2023
1c3c1e2
Merge main to api-locking
Abhicodes-crypto Sep 22, 2023
25e573f
Merge main to api-locking
Abhicodes-crypto Sep 22, 2023
442dee8
refactor: update open api spec
Abhicodes-crypto Sep 22, 2023
14c7bb4
fix: capture request skip deserialize payment_id
Abhicodes-crypto Sep 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge main to api-locking
  • Loading branch information
Abhicodes-crypto committed Sep 22, 2023
commit 1c3c1e2731c6e6dd0ac50b152e828c366478a042
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ migrations/ @juspay/hyperswitch-framework

connector-template/ @juspay/hyperswitch-connector
crates/router/src/connector/ @juspay/hyperswitch-connector
crates/router/tests/connectors @juspay/hyperswitch-connector

crates/router/src/compatibility/ @juspay/hyperswitch-compatibility

Expand Down
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@ All notable changes to HyperSwitch will be documented here.

- - -

## 1.43.1 (2023-09-21)

### Bug Fixes

- Add flow_name setter ([#2234](https://github.com/juspay/hyperswitch/pull/2234)) ([`30e2c90`](https://github.com/juspay/hyperswitch/commit/30e2c906724a610ec5072e3a103eb3ce21a5ef0e))

**Full Changelog:** [`v1.43.0...v1.43.1`](https://github.com/juspay/hyperswitch/compare/v1.43.0...v1.43.1)

- - -


## 1.43.0 (2023-09-21)

### Features

- **connector:** [Gocardless] add support for Ach, Sepa, Becs payment methods ([#2180](https://github.com/juspay/hyperswitch/pull/2180)) ([`3efce90`](https://github.com/juspay/hyperswitch/commit/3efce9013d0572be9162216f134830ccf7e04905))
- **core:** Add support for webhook additional source verification call for paypal ([#2058](https://github.com/juspay/hyperswitch/pull/2058)) ([`2a9e09d`](https://github.com/juspay/hyperswitch/commit/2a9e09d812ca11960cabab289b32be162bc5cfc9))
- **db:** Enable caching for merchant_account fetch using publishable key ([#2186](https://github.com/juspay/hyperswitch/pull/2186)) ([`eb10aca`](https://github.com/juspay/hyperswitch/commit/eb10aca6313b3b3cb1763ca20b54b11c31b93b26))
- **router:** Add kv implementation for address for payment flows ([#2177](https://github.com/juspay/hyperswitch/pull/2177)) ([`afff3e1`](https://github.com/juspay/hyperswitch/commit/afff3e1789b99a586f0b7ff6c5880743a996f565))

### Bug Fixes

- **connector:**
- [trustpay] add missing error_codes ([#2204](https://github.com/juspay/hyperswitch/pull/2204)) ([`8098322`](https://github.com/juspay/hyperswitch/commit/809832213eb0f961853bf0db8b2830a606f9ed37))
- [Trustpay] Add missing error code ([#2212](https://github.com/juspay/hyperswitch/pull/2212)) ([`e4b3cc7`](https://github.com/juspay/hyperswitch/commit/e4b3cc790580f04012dba3d926e170dce4cec5d1))
- **env:** Remove EUR currency from clearpay_afterpay in stripe connector ([#2213](https://github.com/juspay/hyperswitch/pull/2213)) ([`9009ab2`](https://github.com/juspay/hyperswitch/commit/9009ab2896ef9c8df9045c288af5ad601ec7fcd7))

### Refactors

- **router:** Refactor customer <> address in customers and payments flow ([#2158](https://github.com/juspay/hyperswitch/pull/2158)) ([`8ee2ce1`](https://github.com/juspay/hyperswitch/commit/8ee2ce1f4fc416ac33a5e4def22ce2debdc6a6f9))

**Full Changelog:** [`v1.42.0...v1.43.0`](https://github.com/juspay/hyperswitch/compare/v1.42.0...v1.43.0)

- - -


## 1.42.0 (2023-09-20)

### Features
Expand Down
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ ideal = { country = "NL", currency = "EUR" }
[pm_filters.stripe]
google_pay = { country = "AL,DZ,AS,AO,AG,AR,AU,AT,AZ,BH,BY,BE,BR,BG,CA,CL,CO,HR,CZ,DK,DO,EG,EE,FI,FR,DE,GR,HK,HU,IN,ID,IE,IL,IT,JP,JO,KZ,KE,KW,LV,LB,LT,LU,MY,MX,NL,NZ,NO,OM,PK,PA,PE,PH,PL,PT,QA,RO,RU,SA,SG,SK,ZA,ES,LK,SE,CH,TW,TH,TR,UA,AE,GB,US,UY,VN" }
apple_pay = { country = "AU,CN,HK,JP,MO,MY,NZ,SG,TW,AM,AT,AZ,BY,BE,BG,HR,CY,CZ,DK,EE,FO,FI,FR,GE,DE,GR,GL,GG,HU,IS,IE,IM,IT,KZ,JE,LV,LI,LT,LU,MT,MD,MC,ME,NL,NO,PL,PT,RO,SM,RS,SK,SI,ES,SE,CH,UA,GB,AR,CO,CR,BR,MX,PE,BH,IL,JO,KW,PS,QA,SA,AE,CA,UM,US" }
klarna = { country = "AT,BE,DK,FI,FR,DE,IE,IT,NL,NO,ES,SE,GB,US", currency = "EUR,USD,GBP,DKK,SEK,NOK" }
klarna = { country = "US", currency = "USD" }
affirm = { country = "US", currency = "USD" }
afterpay_clearpay = { country = "US,CA,GB,AU,NZ,FR,ES", currency = "USD,CAD,GBP,AUD,NZD,EUR" }
afterpay_clearpay = { country = "US,CA,GB,AU,NZ,FR,ES", currency = "USD,CAD,GBP,AUD,NZD" }
giropay = { country = "DE", currency = "EUR" }
eps = { country = "AT", currency = "EUR" }
sofort = { country = "AT,BE,DE,IT,NL,ES", currency = "EUR" }
Expand Down
2 changes: 1 addition & 1 deletion crates/common_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ strum = { version = "0.24.1", features = ["derive"] }
thiserror = "1.0.40"
time = { version = "0.3.21", features = ["serde", "serde-well-known", "std"] }
tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"], optional = true }
phonenumber = "0.3.2"
phonenumber = "0.3.3"

# First party crates
masking = { version = "0.1.0", path = "../masking" }
Expand Down
5 changes: 3 additions & 2 deletions crates/diesel_models/src/address.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;

use crate::{encryption::Encryption, enums, schema::address};

#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
#[derive(Clone, Debug, Insertable, Serialize, Deserialize, router_derive::DebugAsDisplay)]
#[diesel(table_name = address)]
pub struct AddressNew {
pub address_id: String,
Expand All @@ -25,7 +26,7 @@ pub struct AddressNew {
pub modified_at: PrimitiveDateTime,
}

#[derive(Clone, Debug, Queryable, Identifiable)]
#[derive(Clone, Debug, Queryable, Identifiable, Serialize, Deserialize)]
#[diesel(table_name = address, primary_key(address_id))]
pub struct Address {
pub id: Option<i32>,
Expand Down
2 changes: 2 additions & 0 deletions crates/diesel_models/src/kv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use error_stack::{IntoReport, ResultExt};
use serde::{Deserialize, Serialize};

use crate::{
address::AddressNew,
errors,
payment_attempt::{PaymentAttempt, PaymentAttemptNew, PaymentAttemptUpdate},
payment_intent::{PaymentIntent, PaymentIntentNew, PaymentIntentUpdate},
Expand Down Expand Up @@ -39,6 +40,7 @@ pub enum Insertable {
PaymentIntent(PaymentIntentNew),
PaymentAttempt(PaymentAttemptNew),
Refund(RefundNew),
Address(Box<AddressNew>),
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
4 changes: 4 additions & 0 deletions crates/drainer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ async fn drainer(
let payment_intent = "payment_intent";
let payment_attempt = "payment_attempt";
let refund = "refund";
let address = "address";
match db_op {
// TODO: Handle errors
kv::DBOperation::Insert { insertable } => {
Expand All @@ -170,6 +171,9 @@ async fn drainer(
kv::Insertable::Refund(a) => {
macro_util::handle_resp!(a.insert(&conn).await, insert_op, refund)
}
kv::Insertable::Address(addr) => {
macro_util::handle_resp!(addr.insert(&conn).await, insert_op, address)
}
}
})
.await;
Expand Down
60 changes: 53 additions & 7 deletions crates/router/src/connector/adyen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ impl ConnectorCommon for Adyen {
"adyen"
}

fn get_currency_unit(&self) -> api::CurrencyUnit {
api::CurrencyUnit::Minor
}

fn get_auth_header(
&self,
auth_type: &types::ConnectorAuthType,
Expand Down Expand Up @@ -169,7 +173,13 @@ impl
req,
types::PaymentsAuthorizeData::from(req),
));
let connector_req = adyen::AdyenPaymentRequest::try_from(&authorize_req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
authorize_req.request.currency,
authorize_req.request.amount,
&authorize_req,
))?;
let connector_req = adyen::AdyenPaymentRequest::try_from(&connector_router_data)?;

let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
Expand Down Expand Up @@ -290,7 +300,13 @@ impl
&self,
req: &types::PaymentsCaptureRouterData,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenCaptureRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.amount_to_capture,
req,
))?;
let connector_req = adyen::AdyenCaptureRequest::try_from(&connector_router_data)?;
let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
utils::Encode::<adyen::AdyenCaptureRequest>::encode_to_string_of_json,
Expand Down Expand Up @@ -608,7 +624,13 @@ impl
&self,
req: &types::PaymentsAuthorizeRouterData,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenPaymentRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.amount,
req,
))?;
let connector_req = adyen::AdyenPaymentRequest::try_from(&connector_router_data)?;
let request_body = types::RequestBody::log_and_get_request_body(
&connector_req,
common_utils::ext_traits::Encode::<adyen::AdyenPaymentRequest<'_>>::encode_to_string_of_json,
Expand Down Expand Up @@ -1008,7 +1030,13 @@ impl services::ConnectorIntegration<api::PoCreate, types::PayoutsData, types::Pa
&self,
req: &types::PayoutsRouterData<api::PoCreate>,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenPayoutCreateRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.destination_currency,
req.request.amount,
req,
))?;
let connector_req = adyen::AdyenPayoutCreateRequest::try_from(&connector_router_data)?;
let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
utils::Encode::<adyen::AdyenPayoutCreateRequest>::encode_to_string_of_json,
Expand Down Expand Up @@ -1094,7 +1122,13 @@ impl
&self,
req: &types::PayoutsRouterData<api::PoEligibility>,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenPayoutEligibilityRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.destination_currency,
req.request.amount,
req,
))?;
let connector_req = adyen::AdyenPayoutEligibilityRequest::try_from(&connector_router_data)?;
let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
utils::Encode::<adyen::AdyenPayoutEligibilityRequest>::encode_to_string_of_json,
Expand Down Expand Up @@ -1197,7 +1231,13 @@ impl services::ConnectorIntegration<api::PoFulfill, types::PayoutsData, types::P
&self,
req: &types::PayoutsRouterData<api::PoFulfill>,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenPayoutFulfillRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.destination_currency,
req.request.amount,
req,
))?;
let connector_req = adyen::AdyenPayoutFulfillRequest::try_from(&connector_router_data)?;
let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
utils::Encode::<adyen::AdyenPayoutFulfillRequest>::encode_to_string_of_json,
Expand Down Expand Up @@ -1289,7 +1329,13 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
&self,
req: &types::RefundsRouterData<api::Execute>,
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
let connector_req = adyen::AdyenRefundRequest::try_from(req)?;
let connector_router_data = adyen::AdyenRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.refund_amount,
req,
))?;
let connector_req = adyen::AdyenRefundRequest::try_from(&connector_router_data)?;

let adyen_req = types::RequestBody::log_and_get_request_body(
&connector_req,
Expand Down
Loading