Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(template): Address add_connector.sh throwing errors when creating new connector template (#1679)
Pa1NarK3951561752bf
diff --git a/connector-template/test.rs b/connector-template/test.rsindex d69f697cc2..008e3d50dc 100644--- a/connector-template/test.rs+++ b/connector-template/test.rs@@ -1,4 +1,3 @@-use std::str::FromStr;use masking::Secret;use router::{core::utils as core_utils,diff --git a/scripts/add_connector.sh b/scripts/add_connector.shindex 7d7e919457..aa1651154c 100755--- a/scripts/add_connector.sh+++ b/scripts/add_connector.sh@@ -1,16 +1,18 @@#! /usr/bin/env bash+function find_prev_connector() {self=scripts/add_connector.sh+ # Comment below line to stop undoing changes when the script is triggered, make sure you undo this change before pushinggit checkout $selfcp $self $self.tmp- # add new connector to existing list and sort it+ # Add new connector to existing list and sort itconnectors=(aci adyen airwallex applepay authorizedotnet bambora bitpay bluesnap braintree cashtocode checkout coinbase cryptopay cybersource dlocal dummyconnector fiserv forte globalpay globepay iatapay klarna mollie multisafepay nexinets noon nuvei opayo opennode payeezy payme paypal payu powertranz rapyd shift4 stax stripe trustpay tsys wise worldline worldpay "$1")IFS=$'\n' sorted=($(sort <<<"${connectors[*]}")); unset IFSres=`echo ${sorted[@]}`sed -i'' -e "s/^ connectors=.*/ connectors=($res \"\$1\")/" $self.tmpfor i in "${!sorted[@]}"; doif [ "${sorted[$i]}" = "$1" ] && [ $i != "0" ]; then- # find and return the connector name where this new connector should be added next to it+ # Find and return the connector name where this new connector should be added next to iteval "$2='${sorted[i-1]}'"mv $self.tmp $selfrm $self.tmp-e@@ -19,70 +21,72 @@ function find_prev_connector() {donemv $self.tmp $selfrm $self.tmp-e- # if the new connector needs to be added in first place, add it after Aci, sorted order needs to be covered in code review+ # If the new connector needs to be added in first place, add it after Aci, sorted order needs to be covered in code revieweval "$2='aci'"}-pg=$1;++payment_gateway=$1;base_url=$2;-pgc="$(tr '[:lower:]' '[:upper:]' <<< ${pg:0:1})${pg:1}"+payment_gateway_camelcase="$(tr '[:lower:]' '[:upper:]' <<< ${payment_gateway:0:1})${payment_gateway:1}"src="crates/router/src"conn="$src/connector"tests="../../tests/connectors"+test_utils="../../../test_utils/src"SCRIPT="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"RED='\033[0;31m'GREEN='\033[0;32m'ORANGE='\033[0;33m'-if [ -z "$pg" ] || [ -z "$base_url" ]; then+if [ -z "$payment_gateway" ] || [ -z "$base_url" ]; thenecho "$RED Connector name or base_url not present: try $GREEN\"sh add_connector.sh adyen https://test.adyen.com\""exitficd $SCRIPT/..-# remove template files if already created for this connector-rm -rf $conn/$pg $conn/$pg.rs+# Remove template files if already created for this connector+rm -rf $conn/$payment_gateway $conn/$payment_gateway.rsgit checkout $conn.rs $src/types/api.rs $src/configs/settings.rs config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml crates/api_models/src/enums.rs $src/core/payments/flows.rs-# add enum for this connector in required places-prvc=''-find_prev_connector $1 prvc-prvcc="$(tr '[:lower:]' '[:upper:]' <<< ${prvc:0:1})${prvc:1}"-sed -i'' -e "s|pub mod $prvc;|pub mod $prvc;\npub mod ${pg};|" $conn.rs-sed -i'' -e "s/};/${pg}::${pgc},\n};/" $conn.rs-sed -i'' -e "s|\"$prvc\" \(.*\)|\"$prvc\" \1\n\t\t\t\"${pg}\" => Ok(Box::new(\&connector::${pgc})),|" $src/types/api.rs-sed -i'' -e "s/pub $prvc: \(.*\)/pub $prvc: \1\n\tpub ${pg}: ConnectorParams,/" $src/configs/settings.rs-sed -i'' -e "s|$prvc.base_url \(.*\)|$prvc.base_url \1\n${pg}.base_url = \"$base_url\"|" config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml-sed -r -i'' -e "s/\"$prvc\",/\"$prvc\",\n \"${pg}\",/" config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml-sed -i'' -e "s/pub enum RoutableConnectors {/pub enum RoutableConnectors {\n\t${pgc},/" crates/api_models/src/enums.rs-sed -i'' -e "s/Dummy,/Dummy,\n\t${pgc},/" crates/api_models/src/enums.rs-sed -i'' -e "s/^default_imp_for_\(.*\)/default_imp_for_\1\n\tconnector::${pgc},/" $src/core/payments/flows.rs+# Add enum for this connector in required places+previous_connector=''+find_prev_connector $1 previous_connector+previous_connector_camelcase="$(tr '[:lower:]' '[:upper:]' <<< ${previous_connector:0:1})${previous_connector:1}"+sed -i'' -e "s|pub mod $previous_connector;|pub mod $previous_connector;\npub mod ${payment_gateway};|" $conn.rs+sed -i'' -e "s/};/${payment_gateway}::${payment_gateway_camelcase},\n};/" $conn.rs+sed -i'' -e "s|$previous_connector_camelcase \(.*\)|$previous_connector_camelcase \1\n\t\t\tenums::Connector::${payment_gateway_camelcase} => Ok(Box::new(\&connector::${payment_gateway_camelcase})),|" $src/types/api.rs+sed -i'' -e "s/pub $previous_connector: \(.*\)/pub $previous_connector: \1\n\tpub ${payment_gateway}: ConnectorParams,/" $src/configs/settings.rs+sed -i'' -e "s|$previous_connector.base_url \(.*\)|$previous_connector.base_url \1\n${payment_gateway}.base_url = \"$base_url\"|" config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml+sed -r -i'' -e "s/\"$previous_connector\",/\"$previous_connector\",\n \"${payment_gateway}\",/" config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml+sed -i '' -e "s/\(pub enum Connector {\)/\1\n\t${payment_gateway_camelcase},/" crates/api_models/src/enums.rs+sed -i'' -e "s/\(pub enum RoutableConnectors {\)/\1\n\t${payment_gateway_camelcase},/" crates/api_models/src/enums.rs+sed -i'' -e "s/^default_imp_for_\(.*\)/default_imp_for_\1\n\tconnector::${payment_gateway_camelcase},/" $src/core/payments/flows.rs-# remove temporary files created in above step+# Remove temporary files created in above steprm $conn.rs-e $src/types/api.rs-e $src/configs/settings.rs-e config/development.toml-e config/docker_compose.toml-e config/config.example.toml-e loadtest/config/development.toml-e crates/api_models/src/enums.rs-e $src/core/payments/flows.rs-ecd $conn/-# generate template files for the connector+# Generate template files for the connectorcargo install cargo-generate-cargo gen-pg $pg+cargo gen-pg $payment_gateway-# move sub files and test files to appropriate folder-mv $pg/mod.rs $pg.rs-mv $pg/test.rs ${tests}/$pg.rs+# Move sub files and test files to appropriate folder+mv $payment_gateway/mod.rs $payment_gateway.rs+mv $payment_gateway/test.rs ${tests}/$payment_gateway.rs-# remove changes from tests if already done for this connector-git checkout ${tests}/main.rs ${tests}/connector_auth.rs ${tests}/sample_auth.toml+# Remove changes from tests if already done for this connector+git checkout ${tests}/main.rs ${test_utils}/connector_auth.rs ${tests}/sample_auth.toml-# add enum for this connector in test folder-sed -i'' -e "s/mod utils;/mod ${pg};\nmod utils;/" ${tests}/main.rs-sed -i'' -e "s/ pub $prvc: \(.*\)/\tpub $prvc: \1\n\tpub ${pg}: Option<HeaderKey>,/; s/auth.toml/sample_auth.toml/" ${tests}/connector_auth.rs-echo "\n\n[${pg}]\napi_key=\"API Key\"" >> ${tests}/sample_auth.toml+# Add enum for this connector in test folder+sed -i'' -e "s/mod utils;/mod ${payment_gateway};\nmod utils;/" ${tests}/main.rs+sed -i'' -e "s/ pub $previous_connector: \(.*\)/\tpub $previous_connector: \1\n\tpub ${payment_gateway}: Option<HeaderKey>,/; s/auth.toml/sample_auth.toml/" ${test_utils}/connector_auth.rs+echo "\n\n[${payment_gateway}]\napi_key=\"API Key\"" >> ${tests}/sample_auth.toml-# remove temporary files created in above step-rm ${tests}/main.rs-e ${tests}/connector_auth.rs-e+# Remove temporary files created in above step+rm ${tests}/main.rs-e ${test_utils}/connector_auth.rs-ecargo +nightly fmt --allcargo check-echo "${GREEN}Successfully created connector. Running the tests of $pg.rs"+echo "${GREEN}Successfully created connector. Running the tests of $payment_gateway.rs"-# runs tests for the new connector-cargo test --package router --test connectors -- $pg-echo "${ORANGE}Update your credentials for $pg connector in crates/router/tests/connectors/sample_auth.toml"+# Runs tests for the new connector+cargo test --package router --test connectors -- $payment_gateway+echo "${ORANGE}Update your credentials for $payment_gateway connector in crates/router/tests/connectors/sample_auth.toml"