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(connector): [Noon] Add Card Mandates and Webhooks Support #1243

Merged
merged 25 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a6d8bf9
feat: generate base script code for noon
SamraatBansal May 15, 2023
9043a08
fix: comment noon from connector flow
SamraatBansal May 15, 2023
d5953e4
feat: add card payments for noon
SamraatBansal May 17, 2023
3fb4d3a
chore: Merge branch 'main' into noon-cards-integ
SamraatBansal May 17, 2023
2b39687
feat: add cards 3ds
SamraatBansal May 18, 2023
2f89f2e
chore: Merge branch 'main' into noon-cards-integ
SamraatBansal May 18, 2023
67c5c77
chore: address PR comments
SamraatBansal May 21, 2023
a286da0
chore: Merge branch 'main' into noon-cards-integ
SamraatBansal May 21, 2023
82dd5e9
chore: fmt
SamraatBansal May 21, 2023
5f2b4ba
feat: add card mandates
SamraatBansal May 21, 2023
50789cd
feat: add more payment status
SamraatBansal May 23, 2023
c213300
feat: add webhooks and card mandates
SamraatBansal May 23, 2023
deaa969
chore: Merge branch 'noon-cards-integ' into noon-webhooks-integ
SamraatBansal May 23, 2023
3e31a7a
fix: remove hardcoding from order_category
SamraatBansal May 23, 2023
26cfb1d
chore: add order_categry field in PaymentsAuthorizeRouterData
SamraatBansal May 23, 2023
3f159ec
chore: address PR Comments
SamraatBansal May 23, 2023
1a8636d
fix: spell check
SamraatBansal May 23, 2023
a98de79
chore: Merge branch 'main' into noon-webhooks-integ
SamraatBansal May 23, 2023
aa1fa2c
fix: function naming
SamraatBansal May 24, 2023
e996c57
Merge branch 'main' into noon-webhooks-integ
SamraatBansal May 24, 2023
5b8edb1
fix: remove webhooks_url from connector_request
SamraatBansal May 24, 2023
01b8946
chore: Merge branch 'noon-webhooks-integ' of https://github.com/juspa…
SamraatBansal May 24, 2023
614d628
Merge branch 'main' of https://github.com/juspay/hyperswitch into noo…
ArjunKarthik May 29, 2023
bca01aa
Merge branch 'main' into noon-webhooks-integ
jarnura May 29, 2023
2d9f910
chore: Merge branch 'main' into noon-webhooks-integ
SamraatBansal Jun 5, 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
2 changes: 2 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,8 @@ pub struct Metadata {
#[schema(value_type = Object, example = r#"{ "city": "NY", "unit": "245" }"#)]
#[serde(flatten)]
pub data: pii::SecretSerdeValue,
/// Information about the order category that merchant wants to specify at connector level. (e.g. In Noon Payments it can take values like "pay", "food", or any other custom string set by the merchant in Noon's Dashboard)
pub order_category: Option<String>,
SamraatBansal marked this conversation as resolved.
Show resolved Hide resolved

/// Redirection response coming in request as metadata field only for redirection scenarios
pub redirect_response: Option<RedirectResponse>,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/bluesnap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ impl api::IncomingWebhook for Bluesnap {
let details: bluesnap::BluesnapWebhookObjectResource =
serde_urlencoded::from_bytes(request.body)
.into_report()
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
let res_json =
utils::Encode::<transformers::BluesnapWebhookObjectResource>::encode_to_value(&details)
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
Expand Down
102 changes: 96 additions & 6 deletions crates/router/src/connector/noon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod transformers;
use std::fmt::Debug;

use base64::Engine;
use common_utils::{crypto, ext_traits::ByteSliceExt};
use error_stack::{IntoReport, ResultExt};
use transformers as noon;

Expand All @@ -14,6 +15,7 @@ use crate::{
errors::{self, CustomResult},
payments,
},
db::StorageInterface,
headers,
services::{self, ConnectorIntegration},
types::{
Expand Down Expand Up @@ -579,24 +581,112 @@ impl services::ConnectorRedirectResponse for Noon {

#[async_trait::async_trait]
impl api::IncomingWebhook for Noon {
fn get_webhook_object_reference_id(
fn get_webhook_source_verification_algorithm(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<Box<dyn crypto::VerifySignature + Send>, errors::ConnectorError> {
Ok(Box::new(crypto::HmacSha512))
}

fn get_webhook_source_verification_signature(
&self,
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
let webhook_body: noon::NoonWebhookSignature = request
.body
.parse_struct("NoonWebhookSignature")
.change_context(errors::ConnectorError::WebhookSignatureNotFound)?;
let signature = webhook_body.signature;
consts::BASE64_ENGINE
.decode(signature)
.into_report()
.change_context(errors::ConnectorError::WebhookSignatureNotFound)
}

fn get_webhook_source_verification_message(
&self,
request: &api::IncomingWebhookRequestDetails<'_>,
_merchant_id: &str,
_secret: &[u8],
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
let webhook_body: noon::NoonWebhookBody = request
.body
.parse_struct("NoonWebhookBody")
.change_context(errors::ConnectorError::WebhookSignatureNotFound)?;
let message = format!(
"{},{},{},{},{}",
webhook_body.order_id,
webhook_body.order_status,
webhook_body.event_id,
webhook_body.event_type,
webhook_body.time_stamp,
);
Ok(message.into_bytes())
}

async fn get_webhook_source_verification_merchant_secret(
&self,
db: &dyn StorageInterface,
merchant_id: &str,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
let key = format!("whsec_verification_{}_{}", self.id(), merchant_id);
let secret = match db.find_config_by_key(&key).await {
Ok(config) => Some(config),
Err(e) => {
crate::logger::warn!("Unable to fetch merchant webhook secret from DB: {:#?}", e);
SamraatBansal marked this conversation as resolved.
Show resolved Hide resolved
None
}
};
Ok(secret
.map(|conf| conf.config.into_bytes())
.unwrap_or_default())
}

fn get_webhook_object_reference_id(
&self,
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api::webhooks::ObjectReferenceId, errors::ConnectorError> {
Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
let details: noon::NoonWebhookOrderId = request
.body
.parse_struct("NoonWebhookOrderId")
.change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
api_models::payments::PaymentIdType::ConnectorTransactionId(
details.order_id.to_string(),
),
))
}

fn get_webhook_event_type(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api::IncomingWebhookEvent, errors::ConnectorError> {
Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
let details: noon::NoonWebhookEvent = request
.body
.parse_struct("NoonWebhookEvent")
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;

Ok(match &details.event_type {
noon::NoonWebhookEventTypes::Sale | noon::NoonWebhookEventTypes::Capture => {
match &details.order_status {
noon::NoonPaymentStatus::Captured => {
api::IncomingWebhookEvent::PaymentIntentSuccess
}
_ => Err(errors::ConnectorError::WebhookEventTypeNotFound)?,
}
}
noon::NoonWebhookEventTypes::Fail => api::IncomingWebhookEvent::PaymentIntentFailure,
_ => Err(errors::ConnectorError::WebhookEventTypeNotFound)?,
})
}

fn get_webhook_resource_object(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
Err(errors::ConnectorError::WebhooksNotImplemented).into_report()
let reference_object: serde_json::Value = serde_json::from_slice(request.body)
.into_report()
.change_context(errors::ConnectorError::WebhookResourceObjectNotFound)?;
Ok(reference_object)
}
}
Loading