(purchase, options = {})
| 311 | } |
| 312 | |
| 313 | function isLuckmailPurchaseReusable(purchase, options = {}) { |
| 314 | const normalizedPurchase = normalizeLuckmailPurchase(purchase); |
| 315 | const usedPurchases = normalizeLuckmailUsedPurchases(options.usedPurchases); |
| 316 | const purchaseId = normalizeLuckmailPurchaseId(normalizedPurchase.id); |
| 317 | |
| 318 | if (!isLuckmailPurchaseForProject(normalizedPurchase, options.projectCode || DEFAULT_LUCKMAIL_PROJECT_CODE)) { |
| 319 | return false; |
| 320 | } |
| 321 | if (!normalizedPurchase.email_address || !normalizedPurchase.token) { |
| 322 | return false; |
| 323 | } |
| 324 | if (isLuckmailPurchaseDisabled(normalizedPurchase)) { |
| 325 | return false; |
| 326 | } |
| 327 | if (purchaseId && usedPurchases[purchaseId]) { |
| 328 | return false; |
| 329 | } |
| 330 | if (isLuckmailPurchasePreserved(normalizedPurchase, options)) { |
| 331 | return false; |
| 332 | } |
| 333 | if (isLuckmailPurchaseExpired(normalizedPurchase, options.now || Date.now())) { |
| 334 | return false; |
| 335 | } |
| 336 | return true; |
| 337 | } |
| 338 | |
| 339 | function filterReusableLuckmailPurchases(purchases, options = {}) { |
| 340 | const list = Array.isArray(purchases) |
no test coverage detected