@@ -5,6 +5,7 @@ protocol ReceiptEligibilityUseCaseProtocol {
5
5
func isEligibleForBackendReceipts( onCompletion: @escaping ( Bool ) -> Void )
6
6
func isEligibleForSuccessfulPaymentEmailReceipts( onCompletion: @escaping ( Bool ) -> Void )
7
7
func isEligibleForFailedPaymentEmailReceipts( paymentGatewayID: String , onCompletion: @escaping ( Bool ) -> Void )
8
+ func isEligibleForReceipt( _ orderStatus: OrderStatusEnum , onCompletion: @escaping ( Bool ) -> Void )
8
9
}
9
10
10
11
final class ReceiptEligibilityUseCase : ReceiptEligibilityUseCaseProtocol {
@@ -27,15 +28,10 @@ final class ReceiptEligibilityUseCase: ReceiptEligibilityUseCaseProtocol {
27
28
guard let wcPlugin = wcPlugin, wcPlugin. active else {
28
29
return onCompletion ( false )
29
30
}
30
- // 2. If WooCommerce version is any of the specific API development branches, mark as eligible
31
- if Constants . BackendReceipt. wcPluginDevVersion. contains ( wcPlugin. version) {
32
- onCompletion ( true )
33
- } else {
34
- // 3. Else, if WooCommerce version is higher than minimum required version, mark as eligible
35
- let isSupported = VersionHelpers . isVersionSupported ( version: wcPlugin. version,
36
- minimumRequired: Constants . BackendReceipt. wcPluginMinimumVersion)
37
- onCompletion ( isSupported)
38
- }
31
+ // 2. If WooCommerce version is higher than minimum required version, mark as eligible
32
+ let isSupported = VersionHelpers . isVersionSupported ( version: wcPlugin. version,
33
+ minimumRequired: Constants . BackendReceipt. wcPluginMinimumVersion)
34
+ onCompletion ( isSupported)
39
35
}
40
36
stores. dispatch ( action)
41
37
}
@@ -90,6 +86,26 @@ final class ReceiptEligibilityUseCase: ReceiptEligibilityUseCaseProtocol {
90
86
onCompletion ( isWooCommerceSupported && isGatewaySupported)
91
87
}
92
88
}
89
+
90
+ func isEligibleForReceipt( _ orderStatus: OrderStatusEnum , onCompletion: @escaping ( Bool ) -> Void ) {
91
+ switch orderStatus {
92
+ case . completed, . processing, . refunded:
93
+ isEligibleForBackendReceipts { isEligibleForReceipt in
94
+ onCompletion ( isEligibleForReceipt)
95
+ }
96
+ case . failed:
97
+ selectedPaymentGatewayID { [ weak self] gatewayID in
98
+ guard let gatewayID else {
99
+ return onCompletion ( false )
100
+ }
101
+ self ? . isEligibleForFailedPaymentEmailReceipts ( paymentGatewayID: gatewayID) { isEligibleForReceipt in
102
+ onCompletion ( isEligibleForReceipt)
103
+ }
104
+ }
105
+ default :
106
+ return onCompletion ( false )
107
+ }
108
+ }
93
109
}
94
110
95
111
private extension ReceiptEligibilityUseCase {
@@ -102,11 +118,6 @@ private extension ReceiptEligibilityUseCase {
102
118
return continuation. resume ( returning: false )
103
119
}
104
120
105
- // Checking for concrete versions to cover dev and beta versions
106
- if plugin. version. contains ( minimumVersion) {
107
- return continuation. resume ( returning: true )
108
- }
109
-
110
121
// If plugin version is higher than minimum required version, mark as eligible
111
122
let isSupported = VersionHelpers . isVersionSupported ( version: plugin. version,
112
123
minimumRequired: minimumVersion)
@@ -115,6 +126,15 @@ private extension ReceiptEligibilityUseCase {
115
126
stores. dispatch ( action)
116
127
}
117
128
}
129
+
130
+ // Returns the current payment gateway ID, needed when checking if a transaction is eligible for receipts
131
+ // based on which plugin and versions are active
132
+ private func selectedPaymentGatewayID( onCompletion: @escaping ( String ? ) -> Void ) {
133
+ let action = CardPresentPaymentAction . selectedPaymentGatewayAccount { paymentGatewayAccount in
134
+ onCompletion ( paymentGatewayAccount? . gatewayID)
135
+ }
136
+ stores. dispatch ( action)
137
+ }
118
138
}
119
139
120
140
private extension ReceiptEligibilityUseCase {
@@ -123,7 +143,6 @@ private extension ReceiptEligibilityUseCase {
123
143
124
144
enum BackendReceipt {
125
145
static let wcPluginMinimumVersion = " 8.7.0 "
126
- static let wcPluginDevVersion : [ String ] = [ " 8.7.0-dev " , " 8.6.0-dev " ]
127
146
}
128
147
129
148
enum ReceiptAfterPayment {
0 commit comments