Skip to content

Commit

Permalink
Merge branch 'main' of github.com:juspay/hyperswitch into filter_pmd_…
Browse files Browse the repository at this point in the history
…mandates
  • Loading branch information
Chethan-rao committed Jul 11, 2023
2 parents b555331 + 865db94 commit 8a26d0a
Show file tree
Hide file tree
Showing 30 changed files with 1,796 additions and 1,455 deletions.
8 changes: 7 additions & 1 deletion .github/scripts/run_ui_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ while netstat -lnt | awk '$4 ~ /:8080$/ {exit 1}'; do
else
sleep 10
fi
done
done

IN="$INPUT"
for i in $(echo $IN | tr "," "\n"); do
cargo test --package router --test connectors -- "${i}_ui::" --test-threads=1 >> tests/test_results.log 2>&1
done
cat tests/test_results.log
2,306 changes: 1,171 additions & 1,135 deletions .github/testcases/ui_tests.json

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions .github/workflows/connector-ui-sanity-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ jobs:
connector:
# do not use more than 8 runners, try to group less time taking connectors together
- stripe
- adyen_uk|shift4|worldline
- airwallex|bluesnap|checkout
- paypal|mollie|payu
- adyen_uk,shift4,worldline
- airwallex,bluesnap,checkout
- paypal,mollie,payu

steps:
- name: Checkout repository
Expand All @@ -101,8 +101,8 @@ jobs:
- name: Install latest compiler
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
toolchain: stable

- uses: Swatinem/[email protected]

- uses: baptiste0928/[email protected]
Expand All @@ -111,23 +111,26 @@ jobs:
features: postgres
args: "--no-default-features"

- name: diesel migration run
- name: Diesel migration run
shell: bash
env:
DATABASE_URL: postgres://db_user:db_pass@localhost:5432/hyperswitch_db
run: diesel migration run

- name: Start server
- name: Start server and run tests
env:
UI_TESTCASES_PATH: ${{ secrets.UI_TESTCASES_PATH }}
INPUT: ${{ matrix.connector }}
shell: bash
run: sh .github/scripts/run_ui_tests.sh

- name: Run tests
- name: View test results
shell: bash
run: cat tests/test_results.log

- name: Check test results
shell: bash
run: |
IN="${{ matrix.connector }}"
connectors=(${IN//|/ })
for i in "${connectors[@]}"; do
cargo test --package router --test connectors -- "${i}_ui::" --test-threads=1
done
if test "$( grep 'test result: FAILED' -r tests/test_results.log | wc -l )" -gt "0"; then
exit 1
fi
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RegioBank = "RegioBank"
SOM = "SOM" # Somalia country code
THA = "THA" # Thailand country code
ZAR = "ZAR" # South African Rand currency code
klick = "klick" # Swedish word for clicks

[default.extend-words]
aci = "aci" # Name of a connector
Expand Down
3 changes: 3 additions & 0 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,6 @@ wallet.google_pay = {connector_list = "stripe,adyen"}
wallet.apple_pay = {connector_list = "stripe,adyen"}
card.credit = {connector_list = "stripe,adyen,authorizedotnet,globalpay,worldpay,multisafepay,nmi,nexinets,noon"}
card.debit = {connector_list = "stripe,adyen,authorizedotnet,globalpay,worldpay,multisafepay,nmi,nexinets,noon"}

[connector_request_reference_id_config]
merchant_ids_send_payment_id_as_connector_request_id = []
14 changes: 14 additions & 0 deletions crates/api_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,20 @@ pub struct UnresolvedResponseReason {
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum FieldType {
UserFullName,
UserEmailAddress,
UserPhoneNumber,
UserCountry { options: Vec<String> },
UserAddressline1,
UserAddressline2,
UserAddressCity,
UserAddressPincode,
UserAddressState,
UserAddressCountry,
UserBlikCode,
FieldsComplete,
UserBillingName,
UserBank,
Text,
DropDown { options: Vec<String> },
}
Expand Down
295 changes: 163 additions & 132 deletions crates/router/src/configs/defaults.rs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions crates/router/src/configs/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub struct Settings {
pub mandates: Mandates,
pub required_fields: RequiredFields,
pub delayed_session_response: DelayedSessionConfig,
pub connector_request_reference_id_config: ConnectorRequestReferenceIdConfig,
}

#[derive(Debug, Deserialize, Clone, Default)]
Expand Down Expand Up @@ -558,6 +559,11 @@ pub struct DelayedSessionConfig {
pub connectors_with_delayed_session_response: HashSet<api_models::enums::Connector>,
}

#[derive(Debug, Deserialize, Clone, Default)]
pub struct ConnectorRequestReferenceIdConfig {
pub merchant_ids_send_payment_id_as_connector_request_id: HashSet<String>,
}

fn delayed_session_deser<'a, D>(
deserializer: D,
) -> Result<HashSet<api_models::enums::Connector>, D::Error>
Expand Down
5 changes: 4 additions & 1 deletion crates/router/src/connector/paypal/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl TryFrom<&types::ConnectorAuthType> for PaypalAuthType {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum PaypalOrderStatus {
Pending,
Completed,
Voided,
Created,
Expand All @@ -246,7 +247,9 @@ impl ForeignFrom<(PaypalOrderStatus, PaypalPaymentIntent)> for storage_enums::At
}
}
PaypalOrderStatus::Voided => Self::Voided,
PaypalOrderStatus::Created | PaypalOrderStatus::Saved => Self::Pending,
PaypalOrderStatus::Created | PaypalOrderStatus::Saved | PaypalOrderStatus::Pending => {
Self::Pending
}
PaypalOrderStatus::Approved => Self::AuthenticationSuccessful,
PaypalOrderStatus::PayerActionRequired => Self::AuthenticationPending,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/stripe/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ impl TryFrom<&types::VerifyRouterData> for SetupIntentRequest {
metadata_txn_id,
metadata_txn_uuid,
payment_data,
return_url: item.return_url.clone(),
return_url: item.request.router_return_url.clone(),
off_session: item.request.off_session,
usage: item.request.setup_future_usage,
payment_method_options: None,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,7 @@ pub fn router_data_type_conversion<F1, F2, Req1, Req2, Res1, Res2>(
customer_id: router_data.customer_id,
connector_customer: router_data.connector_customer,
preprocessing_id: router_data.preprocessing_id,
connector_request_reference_id: router_data.connector_request_reference_id,
}
}

Expand Down
16 changes: 12 additions & 4 deletions crates/router/src/core/payments/operations/payment_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
payment_method_type,
request,
browser_info,
db,
state,
)
.await?,
storage_scheme,
Expand Down Expand Up @@ -496,7 +496,7 @@ impl PaymentCreate {
payment_method_type: Option<enums::PaymentMethodType>,
request: &api::PaymentsRequest,
browser_info: Option<serde_json::Value>,
db: &dyn StorageInterface,
state: &AppState,
) -> RouterResult<storage::PaymentAttemptNew> {
let created_at @ modified_at @ last_synced = Some(common_utils::date_time::now());
let status =
Expand All @@ -507,19 +507,27 @@ impl PaymentCreate {
.payment_method_data
.as_ref()
.async_map(|payment_method_data| async {
helpers::get_additional_payment_data(payment_method_data, db).await
helpers::get_additional_payment_data(payment_method_data, &*state.store).await
})
.await
.as_ref()
.map(Encode::<api_models::payments::AdditionalPaymentData>::encode_to_value)
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to encode additional pm data")?;
let attempt_id = if core_utils::is_merchant_enabled_for_payment_id_as_connector_request_id(
&state.conf,
merchant_id,
) {
payment_id.to_string()
} else {
utils::get_payment_attempt_id(payment_id, 1)
};

Ok(storage::PaymentAttemptNew {
payment_id: payment_id.to_string(),
merchant_id: merchant_id.to_string(),
attempt_id: utils::get_payment_attempt_id(payment_id, 1),
attempt_id,
status,
currency,
amount: amount.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::VerifyRequest> for Paym
merchant_id,
request.payment_method,
request,
state,
),
storage_scheme,
)
Expand Down Expand Up @@ -299,14 +300,23 @@ impl PaymentMethodValidate {
merchant_id: &str,
payment_method: Option<api_enums::PaymentMethod>,
_request: &api::VerifyRequest,
state: &AppState,
) -> storage::PaymentAttemptNew {
let created_at @ modified_at @ last_synced = Some(date_time::now());
let status = storage_enums::AttemptStatus::Pending;
let attempt_id = if core_utils::is_merchant_enabled_for_payment_id_as_connector_request_id(
&state.conf,
merchant_id,
) {
payment_id.to_string()
} else {
utils::get_payment_attempt_id(payment_id, 1)
};

storage::PaymentAttemptNew {
payment_id: payment_id.to_string(),
merchant_id: merchant_id.to_string(),
attempt_id: utils::get_payment_attempt_id(payment_id, 1),
attempt_id,
status,
// Amount & Currency will be zero in this case
amount: 0,
Expand Down
15 changes: 15 additions & 0 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
core::{
errors::{self, RouterResponse, RouterResult},
payments::{self, helpers},
utils as core_utils,
},
routes::{metrics, AppState},
services::{self, RedirectForm},
Expand Down Expand Up @@ -122,6 +123,11 @@ where
reference_id: None,
payment_method_token: payment_data.pm_token,
connector_customer: payment_data.connector_customer_id,
connector_request_reference_id: core_utils::get_connector_request_reference_id(
&state.conf,
&merchant_account.merchant_id,
&payment_data.payment_attempt,
),
preprocessing_id: payment_data.payment_attempt.preprocessing_step_id,
};

Expand Down Expand Up @@ -928,6 +934,14 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::VerifyRequestDat
connector_name,
payment_data.creds_identifier.as_deref(),
));
let browser_info: Option<types::BrowserInformation> = attempt
.browser_info
.clone()
.map(|b| b.parse_value("BrowserInformation"))
.transpose()
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "browser_info",
})?;
Ok(Self {
currency: payment_data.currency,
confirm: true,
Expand All @@ -942,6 +956,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::VerifyRequestDat
router_return_url,
email: payment_data.email,
return_url: payment_data.payment_intent.return_url,
browser_info,
payment_method_type: attempt.payment_method_type.clone(),
})
}
Expand Down
Loading

0 comments on commit 8a26d0a

Please sign in to comment.