Skip to content

Commit

Permalink
feat(connector): [cryptopay] add new connector cryptopay, authorize, …
Browse files Browse the repository at this point in the history
…sync, webhook and testcases (#1511)

Co-authored-by: arvindpatel24 <arvind.patel@juspay.in>
  • Loading branch information
arvindpatel24 and arvindpatel24 committed Jun 30, 2023
1 parent 15c2a70 commit 7bb0aa5
Show file tree
Hide file tree
Showing 24 changed files with 872 additions and 15 deletions.
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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`
unsuccess = "unsuccess" # Used in cryptopay request

[files]
extend-exclude = [
Expand Down
2 changes: 2 additions & 0 deletions config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ braintree.base_url = "https://api.sandbox.braintreegateway.com/"
cashtocode.base_url = "https://cluster05.api-test.cashtocode.com"
checkout.base_url = "https://api.sandbox.checkout.com/"
coinbase.base_url = "https://api.commerce.coinbase.com"
cryptopay.base_url = "https://business-sandbox.cryptopay.me"
cybersource.base_url = "https://apitest.cybersource.com/"
dlocal.base_url = "https://sandbox.dlocal.com/"
dummyconnector.base_url = "http://localhost:8080/dummy-connector"
Expand Down Expand Up @@ -215,6 +216,7 @@ cards = [
"adyen",
"authorizedotnet",
"coinbase",
"cryptopay",
"braintree",
"checkout",
"cybersource",
Expand Down
2 changes: 2 additions & 0 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ cards = [
"braintree",
"checkout",
"coinbase",
"cryptopay",
"cybersource",
"dlocal",
"dummyconnector",
Expand Down Expand Up @@ -118,6 +119,7 @@ braintree.base_url = "https://api.sandbox.braintreegateway.com/"
cashtocode.base_url = "https://cluster05.api-test.cashtocode.com"
checkout.base_url = "https://api.sandbox.checkout.com/"
coinbase.base_url = "https://api.commerce.coinbase.com"
cryptopay.base_url = "https://business-sandbox.cryptopay.me"
cybersource.base_url = "https://apitest.cybersource.com/"
dlocal.base_url = "https://sandbox.dlocal.com/"
dummyconnector.base_url = "http://localhost:8080/dummy-connector"
Expand Down
2 changes: 2 additions & 0 deletions config/docker_compose.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ braintree.base_url = "https://api.sandbox.braintreegateway.com/"
cashtocode.base_url = "https://cluster05.api-test.cashtocode.com"
checkout.base_url = "https://api.sandbox.checkout.com/"
coinbase.base_url = "https://api.commerce.coinbase.com"
cryptopay.base_url = "https://business-sandbox.cryptopay.me"
cybersource.base_url = "https://apitest.cybersource.com/"
dlocal.base_url = "https://sandbox.dlocal.com/"
dummyconnector.base_url = "http://localhost:8080/dummy-connector"
Expand Down Expand Up @@ -127,6 +128,7 @@ cards = [
"braintree",
"checkout",
"coinbase",
"cryptopay",
"cybersource",
"dlocal",
"dummyconnector",
Expand Down
2 changes: 2 additions & 0 deletions crates/api_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ pub enum Connector {
Cashtocode,
Checkout,
Coinbase,
Cryptopay,
Cybersource,
Iatapay,
#[cfg(feature = "dummy_connector")]
Expand Down Expand Up @@ -699,6 +700,7 @@ pub enum RoutableConnectors {
Cashtocode,
Checkout,
Coinbase,
Cryptopay,
Cybersource,
Dlocal,
Fiserv,
Expand Down
4 changes: 3 additions & 1 deletion crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,9 @@ pub struct SepaAndBacsBillingDetails {

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub struct CryptoData {}
pub struct CryptoData {
pub pay_currency: Option<String>,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct SofortBilling {
Expand Down
28 changes: 28 additions & 0 deletions crates/common_utils/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,34 @@ impl DecodeMessage for NoAlgorithm {
}
}

/// Represents the HMAC-SHA-1 algorithm
#[derive(Debug)]
pub struct HmacSha1;

impl SignMessage for HmacSha1 {
fn sign_message(
&self,
secret: &[u8],
msg: &[u8],
) -> CustomResult<Vec<u8>, errors::CryptoError> {
let key = hmac::Key::new(hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY, secret);
Ok(hmac::sign(&key, msg).as_ref().to_vec())
}
}

impl VerifySignature for HmacSha1 {
fn verify_signature(
&self,
secret: &[u8],
signature: &[u8],
msg: &[u8],
) -> CustomResult<bool, errors::CryptoError> {
let key = hmac::Key::new(hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY, secret);

Ok(hmac::verify(&key, msg, signature).is_ok())
}
}

/// Represents the HMAC-SHA-256 algorithm
#[derive(Debug)]
pub struct HmacSha256;
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/configs/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ pub struct Connectors {
pub cashtocode: ConnectorParams,
pub checkout: ConnectorParams,
pub coinbase: ConnectorParams,
pub cryptopay: ConnectorParams,
pub cybersource: ConnectorParams,
pub dlocal: ConnectorParams,
#[cfg(feature = "dummy_connector")]
Expand Down
13 changes: 7 additions & 6 deletions crates/router/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod braintree;
pub mod cashtocode;
pub mod checkout;
pub mod coinbase;
pub mod cryptopay;
pub mod cybersource;
pub mod dlocal;
#[cfg(feature = "dummy_connector")]
Expand Down Expand Up @@ -44,10 +45,10 @@ pub use self::dummyconnector::DummyConnector;
pub use self::{
aci::Aci, adyen::Adyen, airwallex::Airwallex, authorizedotnet::Authorizedotnet,
bambora::Bambora, bitpay::Bitpay, bluesnap::Bluesnap, braintree::Braintree,
cashtocode::Cashtocode, checkout::Checkout, coinbase::Coinbase, cybersource::Cybersource,
dlocal::Dlocal, fiserv::Fiserv, forte::Forte, globalpay::Globalpay, iatapay::Iatapay,
klarna::Klarna, mollie::Mollie, multisafepay::Multisafepay, nexinets::Nexinets, nmi::Nmi,
noon::Noon, nuvei::Nuvei, opayo::Opayo, opennode::Opennode, payeezy::Payeezy, payme::Payme,
paypal::Paypal, payu::Payu, rapyd::Rapyd, shift4::Shift4, stripe::Stripe, trustpay::Trustpay,
worldline::Worldline, worldpay::Worldpay, zen::Zen,
cashtocode::Cashtocode, checkout::Checkout, coinbase::Coinbase, cryptopay::Cryptopay,
cybersource::Cybersource, dlocal::Dlocal, fiserv::Fiserv, forte::Forte, globalpay::Globalpay,
iatapay::Iatapay, klarna::Klarna, mollie::Mollie, multisafepay::Multisafepay,
nexinets::Nexinets, nmi::Nmi, noon::Noon, nuvei::Nuvei, opayo::Opayo, opennode::Opennode,
payeezy::Payeezy, payme::Payme, paypal::Paypal, payu::Payu, rapyd::Rapyd, shift4::Shift4,
stripe::Stripe, trustpay::Trustpay, worldline::Worldline, worldpay::Worldpay, zen::Zen,
};
Loading

0 comments on commit 7bb0aa5

Please sign in to comment.