Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Feb 28, 2023

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates

Description

Added support for incoming refund webhooks.

Additional Changes

  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

Manually tested
Webhook Request
image

Outgoing webhook to merchant
image

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

@ghost ghost requested review from a team, ashokkjag and jarnura as code owners February 28, 2023 09:45
@SanchithHegde SanchithHegde assigned ghost Feb 28, 2023
@SanchithHegde SanchithHegde added A-core Area: Core flows C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Feb 28, 2023
Copy link
Member

@SanchithHegde SanchithHegde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that, looks good to me!

Comment on lines 737 to 740
"AUTHORISATION" => api::IncomingWebhookEvent::PaymentIntentSuccess,
"REFUND" => api::IncomingWebhookEvent::RefundSuccess,
"CANCEL_OR_REFUND" => api::IncomingWebhookEvent::RefundSuccess,
"REFUND_FAILED" => api::IncomingWebhookEvent::RefundFailure,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these event codes have been documented on their docs, please convert this to an enum instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Comment on lines 146 to 150
CREATE TYPE "EventClass" AS ENUM ('payments', 'refunds');

CREATE TYPE "EventObjectType" AS ENUM ('payment_details');
CREATE TYPE "EventObjectType" AS ENUM ('payment_details', 'refund_details');

CREATE TYPE "EventType" AS ENUM ('payment_succeeded');
CREATE TYPE "EventType" AS ENUM ('payment_succeeded', 'refund_succeeded', 'refund_failed');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add new migrations for these changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, adding the migrations

Copy link
Member

@SanchithHegde SanchithHegde Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert changes made to this old migrations file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

@SanchithHegde SanchithHegde added S-waiting-on-author Status: This PR is incomplete or needs to address review comments and removed S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Feb 28, 2023
Comment on lines 992 to 1002
#[derive(Debug, Deserialize)]
pub enum WebhookEventCode {
#[serde(rename = "AUTHORISATION")]
Authorisation,
#[serde(rename = "REFUND")]
Refund,
#[serde(rename = "CANCEL_OR_REFUND")]
CancelOrRefund,
#[serde(rename = "REFUND_FAILED")]
RefundFailed,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[derive(Debug, Deserialize)]
pub enum WebhookEventCode {
#[serde(rename = "AUTHORISATION")]
Authorisation,
#[serde(rename = "REFUND")]
Refund,
#[serde(rename = "CANCEL_OR_REFUND")]
CancelOrRefund,
#[serde(rename = "REFUND_FAILED")]
RefundFailed,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")
pub enum WebhookEventCode {
Authorisation,
Refund,
CancelOrRefund,
RefundFailed,
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!

@SanchithHegde SanchithHegde self-requested a review February 28, 2023 11:48
SanchithHegde
SanchithHegde previously approved these changes Feb 28, 2023
Copy link
Member

@SanchithHegde SanchithHegde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the pg_enum table being modified in the down.sql file, looks good to me!

Comment on lines 992 to 1000
#[derive(Debug, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum WebhookEventCode {
Authorisation,
Refund,
CancelOrRefund,
RefundFailed,
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derive strum::Display and annotate with #[strum(serialize_all = "SCREAMING_SNAKE_CASE")] to get a display implementation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


let message = format!(
"{}:{}:{}:{}:{}:{}:{}:{}",
"{}:{}:{}:{}:{}:{}:{:?}:{}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a display implementation for event_code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

vspecky
vspecky previously approved these changes Feb 28, 2023
Copy link
Contributor

@vspecky vspecky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ghost ghost requested a review from SanchithHegde February 28, 2023 12:33
SanchithHegde
SanchithHegde previously approved these changes Feb 28, 2023
Comment on lines 736 to 742
Ok(match notif.event_code {
adyen::WebhookEventCode::Authorisation => {
api::IncomingWebhookEvent::PaymentIntentSuccess
}
adyen::WebhookEventCode::Refund => api::IncomingWebhookEvent::RefundSuccess,
adyen::WebhookEventCode::CancelOrRefund => api::IncomingWebhookEvent::RefundSuccess,
adyen::WebhookEventCode::RefundFailed => api::IncomingWebhookEvent::RefundFailure,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be converted to From implementation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

jarnura
jarnura previously approved these changes Feb 28, 2023
@ghost ghost dismissed stale reviews from jarnura and SanchithHegde via 8327c6b February 28, 2023 13:24
dracarys18
dracarys18 previously approved these changes Feb 28, 2023
@jarnura jarnura added S-waiting-on-review Status: This PR has been implemented and needs to be reviewed and removed S-waiting-on-author Status: This PR is incomplete or needs to address review comments labels Feb 28, 2023
Copy link
Contributor

@vspecky vspecky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jarnura jarnura removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Feb 28, 2023
@jarnura jarnura merged commit f12abbc into main Feb 28, 2023
@jarnura jarnura deleted the incoming-refund-webhook-flow branch February 28, 2023 13:45
@jarnura jarnura added the M-database-changes Metadata: This PR involves database schema changes label Feb 28, 2023
@sai-harsha-vardhan sai-harsha-vardhan self-assigned this Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment