-
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 893a30d
Showing
20 changed files
with
935 additions
and
559 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
34 changes: 34 additions & 0 deletions
34
...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,34 @@ | ||
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) { | ||
|
||
const aclAllowed = this._acl.can('mollie_refund_manager:read'); | ||
|
||
if (!aclAllowed) { | ||
return false; | ||
} | ||
|
||
let refundManagerPossible = false; | ||
|
||
await this._configService.getRefundManagerConfig(salesChannelId).then((response) => { | ||
refundManagerPossible = response.enabled; | ||
}); | ||
|
||
return refundManagerPossible; | ||
} | ||
|
||
} |
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
93 changes: 93 additions & 0 deletions
93
.../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,93 @@ | ||
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.