-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOL-1244: fix refund manager for swag commercial plugin
- Loading branch information
1 parent
159513e
commit 7bca167
Showing
20 changed files
with
959 additions
and
554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ministration/src/module/mollie-payments/components/mollie-refund-manager/RefundManager.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default class RefundManager { | ||
|
||
/** | ||
* | ||
* @param configService | ||
* @param acl | ||
*/ | ||
constructor(configService, acl) { | ||
this._configService = configService; | ||
this._acl = acl; | ||
} | ||
|
||
/** | ||
* Gets if the refund manager is available | ||
* @returns {boolean} | ||
*/ | ||
async isRefundManagerAvailable(salesChannelId) { | ||
let refundManagerPossible = false; | ||
|
||
await this._configService.getRefundManagerConfig(salesChannelId).then((response) => { | ||
refundManagerPossible = response.enabled; | ||
}); | ||
|
||
if (!refundManagerPossible) { | ||
return false; | ||
} | ||
|
||
return this._acl.can('mollie_refund_manager:read'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
.../administration/src/module/mollie-payments/components/mollie-ship-order/MollieShipping.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import OrderAttributes from '../../../../core/models/OrderAttributes'; | ||
|
||
export default class MollieShipping { | ||
|
||
|
||
/** | ||
* | ||
* @param shippingService | ||
*/ | ||
constructor(shippingService) { | ||
this._shippingService = shippingService; | ||
} | ||
|
||
/** | ||
* | ||
* @param order | ||
* @returns {boolean} | ||
*/ | ||
async isShippingPossible(order) { | ||
|
||
const orderAttributes = new OrderAttributes(order); | ||
|
||
// this can happen on subscription renewals...they have no order id | ||
// and therefore the order cannot be shipped | ||
if (orderAttributes.getOrderId() === '') { | ||
return false; | ||
} | ||
|
||
const items = await this.getShippableItems(order); | ||
|
||
for (let i = 0; i < items.length; i++) { | ||
const lineItem = items[i]; | ||
|
||
if (lineItem.quantity > 0) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* | ||
* @param order | ||
* @returns {Promise<{quantity: *, label: *}[]>} | ||
*/ | ||
async getShippableItems(order) { | ||
// load the already shipped items | ||
// so that we can calculate what is left to be shipped | ||
await this._shippingService | ||
.status({ | ||
orderId: order.id, | ||
}) | ||
.then((response) => { | ||
this.shippedLineItems = response; | ||
}); | ||
|
||
const finalItems = []; | ||
|
||
for (let i = 0; i < order.lineItems.length; i++) { | ||
const lineItem = order.lineItems[i]; | ||
|
||
finalItems.push({ | ||
label: lineItem.label, | ||
quantity: this._shippableQuantity(lineItem), | ||
}); | ||
} | ||
|
||
return finalItems; | ||
|
||
} | ||
|
||
/** | ||
* | ||
* @param item | ||
* @returns {*|number} | ||
* @private | ||
*/ | ||
_shippableQuantity(item) { | ||
|
||
if (this.shippedLineItems === null || this.shippedLineItems === undefined) { | ||
return 0; | ||
} | ||
|
||
const itemShippingStatus = this.shippedLineItems[item.id]; | ||
|
||
if (itemShippingStatus === null || itemShippingStatus === undefined) { | ||
return 0; | ||
} | ||
|
||
return itemShippingStatus.quantityShippable; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...istration/src/module/mollie-payments/components/mollie-ship-order/MollieShippingEvents.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default class MollieShippingEvents { | ||
|
||
/** | ||
* | ||
* @returns {string} | ||
*/ | ||
static get EventShippedOrder() { | ||
return 'mollie-shipped-order'; | ||
} | ||
|
||
} |
Oops, something went wrong.