-
Notifications
You must be signed in to change notification settings - Fork 51
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/accept blue refund #529
Conversation
WalkthroughThe pull request updates the Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
packages/vendure-plugin-accept-blue/CHANGELOG.md (1)
1-3
: Clarify terminology in changelog entry.The changelog entry uses the abbreviation "AC" which might not be immediately clear to all readers. Also, the limitation to "initial" transactions should be explained.
Apply this diff to improve clarity:
- Implemented refunding via admin UI for initial AC transaction + Implemented refunding via admin UI for initial Accept Blue transaction + Note: Refunds are only supported for the initial transaction, not for subsequent transactions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
packages/vendure-plugin-accept-blue/package.json
is excluded by!**/*.json
📒 Files selected for processing (2)
packages/vendure-plugin-accept-blue/CHANGELOG.md
(1 hunks)packages/vendure-plugin-accept-blue/src/api/accept-blue-handler.ts
(2 hunks)
🔇 Additional comments (1)
packages/vendure-plugin-accept-blue/src/api/accept-blue-handler.ts (1)
7-18
: LGTM!
The new imports are correctly added and necessary for the refund implementation.
async createRefund( | ||
ctx: RequestContext, | ||
input: RefundOrderInput, | ||
amount: number, | ||
order: Order, | ||
payment: Payment | ||
): Promise<CreateRefundResult> { | ||
const transactionId = Number(payment.transactionId); // All AC transactions are numbers | ||
const refundResult = await service.refund(ctx, transactionId, input.amount); | ||
if (refundResult.errorCode) { | ||
return { | ||
state: 'Failed', | ||
transactionId: String(refundResult.referenceNumber), | ||
metadata: refundResult, | ||
}; | ||
} | ||
return { | ||
state: 'Failed', | ||
transactionId: String(refundResult.referenceNumber), | ||
metadata: refundResult, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix: Method always returns Failed state
The createRefund method currently returns 'Failed' state for both successful and failed refunds. This will cause all refunds to appear as failed in the admin UI.
Fix the successful case by applying this diff:
if (refundResult.errorCode) {
return {
state: 'Failed',
transactionId: String(refundResult.referenceNumber),
metadata: refundResult,
};
}
return {
- state: 'Failed',
+ state: 'Settled',
transactionId: String(refundResult.referenceNumber),
metadata: refundResult,
};
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async createRefund( | |
ctx: RequestContext, | |
input: RefundOrderInput, | |
amount: number, | |
order: Order, | |
payment: Payment | |
): Promise<CreateRefundResult> { | |
const transactionId = Number(payment.transactionId); // All AC transactions are numbers | |
const refundResult = await service.refund(ctx, transactionId, input.amount); | |
if (refundResult.errorCode) { | |
return { | |
state: 'Failed', | |
transactionId: String(refundResult.referenceNumber), | |
metadata: refundResult, | |
}; | |
} | |
return { | |
state: 'Failed', | |
transactionId: String(refundResult.referenceNumber), | |
metadata: refundResult, | |
}; | |
async createRefund( | |
ctx: RequestContext, | |
input: RefundOrderInput, | |
amount: number, | |
order: Order, | |
payment: Payment | |
): Promise<CreateRefundResult> { | |
const transactionId = Number(payment.transactionId); // All AC transactions are numbers | |
const refundResult = await service.refund(ctx, transactionId, input.amount); | |
if (refundResult.errorCode) { | |
return { | |
state: 'Failed', | |
transactionId: String(refundResult.referenceNumber), | |
metadata: refundResult, | |
}; | |
} | |
return { | |
state: 'Settled', | |
transactionId: String(refundResult.referenceNumber), | |
metadata: refundResult, | |
}; |
Description
Allow refunding via the admin UI
Checklist
📌 Always:
👍 Most of the time:
📦 For publishable packages:
package.json
CHANGELOG.md
See this example