chore: fix typos and introduce ci check (#390)

This commit is contained in:
Sanchith Hegde
2023-01-17 11:38:47 +05:30
committed by GitHub
parent 006e9a8892
commit 74f6d0025e
28 changed files with 199 additions and 240 deletions

View File

@ -184,3 +184,13 @@ jobs:
# - name: Run tests
# shell: bash
# run: cargo nextest run --all-features
typos:
name: Spell check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3.1.0
- name: Spell check
uses: crate-ci/typos@master

17
.typos.toml Normal file
View File

@ -0,0 +1,17 @@
[default]
check-filename = true
[default.extend-identifiers]
payment_vas = "payment_vas"
PaymentVas = "PaymentVas"
[default.extend-words]
aci = "aci" # Name of a connector
encrypter = "encrypter" # Used by the `ring` crate
nin = "nin" # National identification number, a field used by PayU connector
substituters = "substituters" # Present in `flake.nix`
[files]
extend-exclude = [
"config/redis.conf", # `typos` also checked "AKE" in the file, which is present as a quoted string
]

View File

@ -42,7 +42,7 @@ ARG RUN_ENV=Sandbox
# args for deciding the executable to export. three binaries:
# 1. BINARY=router - for main application
# 2. BINARY=scheduler, SCHEDULER_FLOW=Consumer - part of proces tracker
# 2. BINARY=scheduler, SCHEDULER_FLOW=Consumer - part of process tracker
# 3. BINARY=scheduler, SCHEDULER_FLOW=Producer - part of process tracker
ARG BINARY=router
ARG SCHEDULER_FLOW=Consumer

View File

@ -188,7 +188,7 @@ if [[ ! -x "`command -v psql`" ]] || [[ ! -x "`command -v redis-server`" ]] ; th
install_dep postgresql-contrib # not needed for macos?
install_dep postgresql-devel # needed for diesel_cli in some linux distributions
install_dep postgresql-libs # needed for diesel_cli in some linux distributions
init_start_postgres # installling libpq messes with initdb creating two copies. better to run it better libpq.
init_start_postgres # installing libpq messes with initdb creating two copies. better to run it better libpq.
install_dep libpq-dev || install_dep libpq
else
print_info "Postgres found. skipping..."

View File

@ -8,7 +8,7 @@ This is a guide to contributing new connector to Router. This guide includes ins
- Understanding of the Connector APIs which you wish to integrate with Router
- Setup of Router repository and running it on local
- Access to API credentials for testing the Connector API (you can quickly sign up for sandbox/uat credentials by visting the website of the connector you wish to integrate)
- Access to API credentials for testing the Connector API (you can quickly sign up for sandbox/uat credentials by visiting the website of the connector you wish to integrate)
In Router, there are Connectors and Payment Methods, examples of both are shown below from which the difference is apparent.
@ -53,6 +53,7 @@ sh add_connector.sh <connector-name>
For this tutorial `<connector-name>` would be `checkout`.
The folder structure will be modified as below
```
crates/router/src/connector
├── checkout
@ -76,7 +77,7 @@ The Connector module is implemented as a stateless module, so that you will not
Lets add code in `transformers.rs` file.
A little planning and designing is required for implementing the Requests and Responses of the connector, as it depends on the API spec of the connector.
For example, in case of checkout, the [request](https://api-reference.checkout.com/#tag/Payments) has a required parameter `currency` and few other required parameters in `source`. But the fields in “source” vary depending on the `source type`. An enum is needed to accomodate this in the Request type. You may need to add the serde tags to convert enum into json or url encoded based on your requirements. Here `serde(untagged)` is added to make the whole structure into the proper json acceptable to the connector.
For example, in case of checkout, the [request](https://api-reference.checkout.com/#tag/Payments) has a required parameter `currency` and few other required parameters in `source`. But the fields in “source” vary depending on the `source type`. An enum is needed to accommodate this in the Request type. You may need to add the serde tags to convert enum into json or url encoded based on your requirements. Here `serde(untagged)` is added to make the whole structure into the proper json acceptable to the connector.
Now let's implement Request type for checkout
@ -277,17 +278,19 @@ And the below derive traits
There is a trait bound to implement refunds, if you don't want to implement refunds you can mark them as `todo!()` but code panics when you initiate refunds then.
Dont forget to add logs lines in appropriate places.
Refer to other conector code for trait implementations. mostly tThe rust compiler will guide you to do it easily.
Refer to other connector code for trait implementations. mostly tThe rust compiler will guide you to do it easily.
Feel free to connect with us in case of any queries and if you want to confirm the status mapping.
### **Test the connector**
Try running the tests in `crates/router/tests/connectors/{{connector-name}}.rs`.
All tests should pass and add appropiate tests for connector specific payment flows.
All tests should pass and add appropriate tests for connector specific payment flows.
### **Build payment request and response from json schema**
Some connectors will provide [json schema](https://developer.worldpay.com/docs/access-worldpay/api/references/payments) for each request and response supported. We can directly convert that schema to rust code by using below script. On running the script a `temp.rs` file will be created in `src/connector/<connector-name>` folder
*Note: The code generated may not be production ready and might fail for some case, we have to clean up the code as per our standards.*
_Note: The code generated may not be production ready and might fail for some case, we have to clean up the code as per our standards._
```bash
brew install openapi-generator
@ -297,33 +300,33 @@ openapi-generator generate -g rust -i ${SCHEMA_PATH} -o temp && cat temp/src/m
```
JSON example
```json
{
"openapi": "3.0.1",
"paths": {},
"info": {
"title": "",
"version": ""
},
"components": {
"schemas": {
"PaymentsResponse": {
"type": "object",
"properties": {
"outcome": {
"type": "string"
}
},
"required": [
"outcome"
]
}
}
"openapi": "3.0.1",
"paths": {},
"info": {
"title": "",
"version": ""
},
"components": {
"schemas": {
"PaymentsResponse": {
"type": "object",
"properties": {
"outcome": {
"type": "string"
}
},
"required": ["outcome"]
}
}
}
}
```
YAML example
```yaml
---
openapi: 3.0.1
@ -334,10 +337,10 @@ info:
components:
schemas:
PaymentsResponse:
type: object
properties:
outcome:
type: string
required:
- outcome
type: object
properties:
outcome:
type: string
required:
- outcome
```

View File

@ -1,2 +0,0 @@
![directory image](/docs/imgs/observability_arch.svg)

View File

@ -55,7 +55,7 @@ pub enum ValidationError {
InvalidValue { message: String },
}
/// Cryptograpic algorithm errors
/// Cryptographic algorithm errors
#[derive(Debug, thiserror::Error)]
pub enum CryptoError {
/// The cryptographic algorithm was unable to encode the message

View File

@ -213,7 +213,7 @@ mod pii_masking_strategy_tests {
}
#[test]
fn test_invalid_lient_secret_masking() {
fn test_invalid_client_secret_masking() {
let secret: Secret<String, IpAddress> =
Secret::new("pay_uszFB2QGe9MmLY65ojhT_secret".to_string());
assert_eq!("*** alloc::string::String ***", format!("{:?}", secret));

View File

@ -33,7 +33,7 @@ async fn drainer_handler(
let drainer_result = drainer(store.clone(), max_read_count, stream_name.as_str()).await;
if let Err(_e) = drainer_result {
//TODO: LOG ERRORs
//TODO: LOG errors
}
let flag_stream_name = utils::get_stream_key_flag(store.clone(), stream_index);

View File

@ -56,7 +56,7 @@ pub async fn trim_from_stream(
.map_err(DrainerError::from)
.into_report()?;
// Since xtrim deletes entires below given id excluding the given id.
// Since xtrim deletes entries below given id excluding the given id.
// Hence, deleting the minimum entry id
redis
.stream_delete_entries(stream_name, minimum_entry_id)

View File

@ -738,7 +738,7 @@ pub struct ErrorResponse {
// use super::*;
// #[test]
// fn verify_tranform_from_router_to_adyen_req() {
// fn verify_transform_from_router_to_adyen_req() {
// let router_req = PaymentsRequest {
// amount: 0.0,
// currency: "None".to_string(),

View File

@ -152,7 +152,7 @@ impl
logger::debug!(payment_session_response_braintree=?res);
let response: braintree::BraintreeSessionTokenResponse = res
.response
.parse_struct("braintree SessionTokenReponse")
.parse_struct("braintree SessionTokenResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
types::RouterData::try_from(types::ResponseRouterData {
response,

View File

@ -360,7 +360,7 @@ pub struct StoredCredential {
pub model: Option<Model>,
/// The reason stored credentials are being used to to create a transaction.
pub reason: Option<Reason>,
/// Indiciates the order of this transaction in the sequence of a planned repeating
/// Indicates the order of this transaction in the sequence of a planned repeating
/// transaction processing model.
pub sequence: Option<Sequence>,
}
@ -506,10 +506,10 @@ pub enum GlobalpayPaymentsRequestType {
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Initiator {
/// The transaction was initated by the merchant, who is getting paid by the
/// The transaction was initiated by the merchant, who is getting paid by the
/// payer.'
Merchant,
/// The transaction was initated by the customer who is paying the merchant.
/// The transaction was initiated by the customer who is paying the merchant.
Payer,
}
@ -789,7 +789,7 @@ pub enum Reason {
Resubmission,
}
/// Indiciates the order of this transaction in the sequence of a planned repeating
/// Indicates the order of this transaction in the sequence of a planned repeating
/// transaction processing model.
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]

View File

@ -162,7 +162,7 @@ pub struct Bank {
pub iban: Option<String>,
/// The international identifier code for the bank.
pub identifier_code: Option<String>,
/// The name assocaited with the bank account
/// The name associated with the bank account
pub name: Option<String>,
}

View File

@ -374,7 +374,8 @@ pub struct PayuOrderResponseBuyerData {
phone: Option<String>,
first_name: Option<String>,
last_name: Option<String>,
nin: Option<String>,
#[serde(rename = "nin")]
national_identification_number: Option<String>,
language: Option<String>,
delivery: Option<String>,
customer_id: Option<String>,

View File

@ -155,7 +155,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
let metadata_order_id = item.payment_id.to_string();
let metadata_txn_id = format!("{}_{}_{}", item.merchant_id, item.payment_id, "1");
let metadata_txn_uuid = Uuid::new_v4().to_string(); //Fetch autogenrated txn_uuid from Database.
let metadata_txn_uuid = Uuid::new_v4().to_string(); //Fetch autogenerated txn_uuid from Database.
// let api::PaymentMethod::Card(a) = item.payment_method_data;
// let api::PaymentMethod::Card(a) = item.payment_method_data;
@ -721,7 +721,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for CaptureRequest {
// use super::*;
// #[test]
// fn verify_tranform_from_router_to_stripe_req() {
// fn verify_transform_from_router_to_stripe_req() {
// let router_req = PaymentsRequest {
// amount: 100.0,
// currency: "USD".to_string(),

View File

@ -141,10 +141,10 @@ impl ConnectorIntegration<api::Void, types::PaymentsCancelData, types::PaymentsR
) -> CustomResult<String, errors::ConnectorError> {
let base_url = self.base_url(connectors);
let auth: worldline::AuthType = worldline::AuthType::try_from(&req.connector_auth_type)?;
let merchat_account_id = auth.merchant_account_id;
let merchant_account_id = auth.merchant_account_id;
let payment_id: &str = req.request.connector_transaction_id.as_ref();
Ok(format!(
"{base_url}v1/{merchat_account_id}/payments/{payment_id}/cancel"
"{base_url}v1/{merchant_account_id}/payments/{payment_id}/cancel"
))
}
@ -222,9 +222,9 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
.change_context(errors::ConnectorError::MissingConnectorTransactionID)?;
let base_url = self.base_url(connectors);
let auth = worldline::AuthType::try_from(&req.connector_auth_type)?;
let merchat_account_id = auth.merchant_account_id;
let merchant_account_id = auth.merchant_account_id;
Ok(format!(
"{base_url}v1/{merchat_account_id}/payments/{payment_id}"
"{base_url}v1/{merchant_account_id}/payments/{payment_id}"
))
}
@ -329,8 +329,8 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
) -> CustomResult<String, errors::ConnectorError> {
let base_url = self.base_url(connectors);
let auth = worldline::AuthType::try_from(&req.connector_auth_type)?;
let merchat_account_id = auth.merchant_account_id;
Ok(format!("{base_url}v1/{merchat_account_id}/payments"))
let merchant_account_id = auth.merchant_account_id;
Ok(format!("{base_url}v1/{merchant_account_id}/payments"))
}
fn get_request_body(
@ -436,9 +436,9 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
let payment_id = req.request.connector_transaction_id.clone();
let base_url = self.base_url(connectors);
let auth = worldline::AuthType::try_from(&req.connector_auth_type)?;
let merchat_account_id = auth.merchant_account_id;
let merchant_account_id = auth.merchant_account_id;
Ok(format!(
"{base_url}v1/{merchat_account_id}/payments/{payment_id}/refund"
"{base_url}v1/{merchant_account_id}/payments/{payment_id}/refund"
))
}
@ -532,9 +532,9 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
.clone();
let base_url = self.base_url(connectors);
let auth: worldline::AuthType = worldline::AuthType::try_from(&req.connector_auth_type)?;
let merchat_account_id = auth.merchant_account_id;
let merchant_account_id = auth.merchant_account_id;
Ok(format!(
"{base_url}v1/{merchat_account_id}/refunds/{refund_id}/"
"{base_url}v1/{merchant_account_id}/refunds/{refund_id}/"
))
}

View File

@ -300,15 +300,15 @@ pub enum ProcessTrackerError {
NotImplemented,
#[error("Job not found")]
JobNotFound,
#[error("Recieved Error ApiResponseError: {0}")]
#[error("Received Error ApiResponseError: {0}")]
EApiErrorResponse(error_stack::Report<ApiErrorResponse>),
#[error("Recieved Error StorageError: {0}")]
#[error("Received Error StorageError: {0}")]
EStorageError(error_stack::Report<StorageError>),
#[error("Recieved Error RedisError: {0}")]
#[error("Received Error RedisError: {0}")]
ERedisError(error_stack::Report<RedisError>),
#[error("Recieved Error ParsingError: {0}")]
#[error("Received Error ParsingError: {0}")]
EParsingError(error_stack::Report<ParsingError>),
#[error("Validation Error Recieved: {0}")]
#[error("Validation Error Received: {0}")]
EValidationError(error_stack::Report<ValidationError>),
}

View File

@ -65,7 +65,7 @@ fn create_gpay_session_token(
.parse_value::<payment_types::GpaySessionTokenData>("GpaySessionTokenData")
.change_context(errors::ConnectorError::NoConnectorMetaData)
.attach_printable(format!(
"cannnot parse gpay metadata from the given value {:?}",
"cannot parse gpay metadata from the given value {:?}",
connector_metadata
))
.change_context(errors::ApiErrorResponse::InvalidDataFormat {

View File

@ -280,7 +280,7 @@ async fn test_checkout_refund_failure() {
_ => panic!("Connector transaction id not found"),
};
// Higher amout than that of payment
// Higher amount than that of payment
refund_request.request.refund_amount = 696969;
let response = services::api::execute_connector_processing_step(
&state,

View File

@ -32,7 +32,7 @@ impl utils::Connector for Payu {
#[actix_web::test]
async fn should_authorize_card_payment() {
//Authorize Card Payment in PLN currenct
//Authorize Card Payment in PLN currency
let authorize_response = Payu {}
.authorize_payment(
Some(types::PaymentsAuthorizeData {
@ -42,7 +42,7 @@ async fn should_authorize_card_payment() {
None,
)
.await;
// in Payu need Psync to get status therfore set to pending
// in Payu need Psync to get status therefore set to pending
assert_eq!(authorize_response.status, enums::AttemptStatus::Pending);
if let Some(transaction_id) = utils::get_connector_transaction_id(authorize_response) {
let sync_response = Payu {}

View File

@ -137,7 +137,7 @@ where
/// Constructor of `FormattingLayer`.
///
/// A `name` will be attached to all records during formatting.
/// A `dst_writer` to forward all recrods.
/// A `dst_writer` to forward all records.
///
/// ## Example
/// ```rust
@ -357,7 +357,7 @@ where
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
// Get value of ket "message" or "target" if does not exist.
// Get value of kept "message" or "target" if does not exist.
let mut message = storage
.values
.get("message")

View File

@ -15,7 +15,7 @@ use tracing_subscriber::{layer::Context, Layer};
#[derive(Clone, Debug)]
pub struct StorageSubscription;
/// Sotrage to store key value pairs of spans.
/// Storage to store key value pairs of spans.
/// When new entry is crated it stores it in [HashMap] which is owned by `extensions`.
#[derive(Clone, Debug)]
pub struct Storage<'a> {

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 86 KiB

View File

@ -1146,7 +1146,7 @@ paths:
capture_on: "2022-09-10T10:11:12Z"
amount_to_capture: 6540
amount_capturable: 6540
amount_recieved: 0
amount_received: 0
customer_id: "cus_udst2tfldj6upmye2reztkmm4i"
email: "guest@example.com"
name: "John Doe"
@ -3032,7 +3032,7 @@ components:
minimum: 100
example: 6540
nullable: true
amount_recieved:
amount_received:
type: integer
description: The amount which is already captured from the payment
minimum: 100

File diff suppressed because one or more lines are too long

View File

@ -1890,7 +1890,7 @@
"responseBodyTests": [
{
"key": "message",
"value": "Refund is not allowed for unsuccessfull payment"
"value": "Refund is not allowed for unsuccessful payment"
}
]
}
@ -3623,7 +3623,7 @@
"openApiResponse": "400",
"variations": [
{
"name": "Update Succeded payment",
"name": "Update Succeeded payment",
"overwrites": [
{
"overwriteRequestPathVariables": [

View File

@ -33,7 +33,7 @@ cd $conn/
# generate template files for the connector
cargo install cargo-generate
cargo gen-pg $pg
# move sub files and test files to appropiate folder
# move sub files and test files to appropriate folder
mv $pg/mod.rs $pg.rs
mv $pg/test.rs ${tests}/$pg.rs
# remove changes from tests if already done for this connector