From eb396089d4ee7439a9c4cbaa44ec72f5a03b8537 Mon Sep 17 00:00:00 2001 From: EresDev Date: Tue, 10 Dec 2024 22:50:06 +0500 Subject: [PATCH 01/15] feat: offer new fallback intl mastercard 18732 --- functions/utils/reloadly-lists.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/functions/utils/reloadly-lists.ts b/functions/utils/reloadly-lists.ts index 392255c7..d5ad8e25 100644 --- a/functions/utils/reloadly-lists.ts +++ b/functions/utils/reloadly-lists.ts @@ -2,6 +2,13 @@ // Keep duplicate country names in different lists export const fallbackIntlMastercard = { + country: "United States", + countryCode: "US", + name: "Mastercard Prepaid USD Debit (Virtual only) US", + sku: 18732, +}; + +export const fallbackIntlMastercardOld = { country: "United States", countryCode: "US", name: "Virtual MasterCard International USD US", From b02b336441c156f30a3aad0067f1eda8abc16928 Mon Sep 17 00:00:00 2001 From: EresDev Date: Wed, 11 Dec 2024 10:13:19 +0500 Subject: [PATCH 02/15] refactor: remove dead code --- tests/fixtures/http-mocks.ts | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/tests/fixtures/http-mocks.ts b/tests/fixtures/http-mocks.ts index d8b4f4c9..a5976a16 100644 --- a/tests/fixtures/http-mocks.ts +++ b/tests/fixtures/http-mocks.ts @@ -19,9 +19,6 @@ import { RELOADLY_AUTH_URL, RELOADLY_PRODUCTION_API_URL, RELOADLY_SANDBOX_API_UR * Intercepts the routes and returns a custom payload */ export const httpMocks = [ - // http.get(`${getBaseUrl(true)}/products**`, () => { - // return HttpResponse.json(bestCard); - // }), http.post(RELOADLY_AUTH_URL, () => { return HttpResponse.json({ access_token: "fooBar" }); }), @@ -95,22 +92,4 @@ export const httpMocks = [ http.get(`${RELOADLY_SANDBOX_API_URL}/reports/transactions`, () => { return HttpResponse.json(noTransaction, { status: 200 }); }), - - // http.all(`*`, ({ request }) => { - // console.error(`All http requests are expected to be mocked in unit tests. Following request was not mocked. ${request.url}`); - // return HttpResponse.json( - // { msg: `All http requests are expected to be mocked in unit tests. Following request was not mocked. ${request.url}` }, - // { status: 404 } - // ); - // }), - // http.get(`https://giftcards-sandbox.reloadly.com/products?productName=visa&productCategoryId=1`, () => { - // return HttpResponse.json({ content: [bestCard] }); - // }), - - // http.get(`https://giftcards-sandbox.reloadly.com/products**`, () => { - // return HttpResponse.json([]); - // }), - // http.get(`https://giftcards-sandbox.reloadly.com/products/18598`, () => { - // return HttpResponse.json(bestCard); - // }), ]; From fc74596452508692d3cfb78971b97066e8dbb569 Mon Sep 17 00:00:00 2001 From: EresDev Date: Wed, 11 Dec 2024 14:58:49 +0500 Subject: [PATCH 03/15] test: fix broken tests for /get-best-card with sku 18732 --- .../get-best-card/best-master-card-prod.json | 52 ++++--------------- tests/fixtures/get-best-card/card-18732.json | 42 +++++++++++++++ tests/fixtures/http-mocks.ts | 4 +- tests/fixtures/post-order/card-18732.json | 6 ++- tests/unit/get-best-card.test.ts | 6 +-- 5 files changed, 64 insertions(+), 46 deletions(-) create mode 100644 tests/fixtures/get-best-card/card-18732.json diff --git a/tests/fixtures/get-best-card/best-master-card-prod.json b/tests/fixtures/get-best-card/best-master-card-prod.json index b3d44712..61c95e76 100644 --- a/tests/fixtures/get-best-card/best-master-card-prod.json +++ b/tests/fixtures/get-best-card/best-master-card-prod.json @@ -3,6 +3,7 @@ "productId": 18172, "productName": "Mastercard® Digital Card CAD US", "global": false, + "status": "ACTIVE", "supportsPreOrder": false, "senderFee": 1.0, "senderFeePercentage": 0.0, @@ -15,9 +16,9 @@ "minSenderDenomination": null, "maxSenderDenomination": null, "fixedRecipientDenominations": [150.0], - "fixedSenderDenominations": [112.83], + "fixedSenderDenominations": [110.88], "fixedRecipientToSenderDenominationsMap": { - "150.0": 112.83 + "150.0": 110.88 }, "metadata": {}, "logoUrls": ["https://cdn.reloadly.com/giftcards/e39131b3-1686-4d8a-a95a-78fa2817b9fa.jpeg"], @@ -36,51 +37,17 @@ }, "redeemInstruction": { "concise": "Your Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD", - "verbose": "\"Redeem Instruction:\nYour Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD...\n\n\n\nTerms and condition:\nVirtual card is issued by Pathward®, N.A., Member FDIC, pursuant to license by Mastercard International Incorporated. Mastercard and the circles design are registered trademarks of Mastercard International Incorporated. No cash access or recurring payments. Can be used where Debit Mastercard is accepted online, for phone/mail orders, or in stores that accept mobile wallet. Valid for up to 6 months; unused funds will forfeit after the valid thru date. Terms and conditions apply. See Cardholder Agreement for details https://www.myprepaidcenter.com/page/mastercard-promo-virtual\n\nMastercard is widely accepted globally*, with the exception of certain countries where credit cards are blocked due to economic sanctions or other regulatory restrictions. Specifically, this includes:\nChina, The Democratic People's Republic of Korea (North Korea), The Islamic Republic of Iran, The Syrian Arab Republic, Ukraine, The Bahamas, Barbados, Benin, Burundi, Burkina Faso, Cambodia, The Cayman Islands, Chad, The Central African Republic, Congo, Comoros, Dominican Republic, Cuba, Guinea, Eritrea, Guinea-Bissau, Haiti, Iraq, Lebanon, Laos, Lesotho, Myanmar, Madagascar, Nicaragua, Panama, Somalia, Sudan, South Sudan, Uganda, Venezuela , Yemen, Zimbabwe, Liberia....\n\n\n\nHow to use:\nGo to =\"\"http://www.MyPrepaidCenter.com/redeem\"\">MyPrepaidCenter.com/redeem and enter code\nComplete the online registration page and accept the cardholder agreement and e-sign agreement, then you will be able to view your 16-digit card number, expiration date, security information, where your card can be used, available balance, transaction history, etc.\nPlastic card available upon request. Requesting a plastic card will reduce the card’s value by $3.00 for manufacturing and fulfillment cost, and can take 7-14 business days. \nRecipient can request a plastic card once they have completed the card registration and activation at MyPrepaidCenter.com\"" - } - }, - { - "productId": 18597, - "productName": "Virtual MasterCard International USD US", - "global": false, - "supportsPreOrder": false, - "senderFee": 1.0, - "senderFeePercentage": 2.0, - "discountPercentage": 0.0, - "denominationType": "RANGE", - "recipientCurrencyCode": "USD", - "minRecipientDenomination": 5.0, - "maxRecipientDenomination": 1000.0, - "senderCurrencyCode": "USD", - "minSenderDenomination": 5.0, - "maxSenderDenomination": 1000.0, - "fixedRecipientDenominations": [], - "fixedSenderDenominations": null, - "fixedRecipientToSenderDenominationsMap": null, - "metadata": null, - "logoUrls": ["https://cdn.reloadly.com/giftcards/08ca41fe-e059-4dea-9dde-aff6ec231303.png"], - "brand": { - "brandId": 378, - "brandName": "Mastercard" - }, - "category": { - "id": 1, - "name": "Payment Cards" + "verbose": "\"Redeem Instruction:\nYour Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD...\n\n\n\nTerms and condition:\nVirtual card is issued by Pathward®, N.A., Member FDIC, pursuant to license by Mastercard International Incorporated. Mastercard and the circles design are registered trademarks of Mastercard International Incorporated. No cash access or recurring payments. Can be used where Debit Mastercard is accepted online, for phone/mail orders, or in stores that accept mobile wallet. Valid for up to 6 months; unused funds will forfeit after the valid thru date. Terms and conditions apply. See Cardholder Agreement for details https://www.myprepaidcenter.com/page/mastercard-promo-virtual\n\nMastercard is widely accepted globally*, with the exception of certain countries where credit cards are blocked due to economic sanctions or other regulatory restrictions. Specifically, this includes:\nChina, The Democratic People's Republic of Korea (North Korea), The Islamic Republic of Iran, The Syrian Arab Republic, Ukraine, The Bahamas, Barbados, Benin, Burundi, Burkina Faso, Cambodia, The Cayman Islands, Chad, The Central African Republic, Congo, Comoros, Dominican Republic, Cuba, Guinea, Eritrea, Guinea-Bissau, Haiti, Iraq, Lebanon, Laos, Lesotho, Myanmar, Madagascar, Nicaragua, Nigeria, Panama, Somalia, Sudan, South Sudan, Uganda, Venezuela , Yemen, Zimbabwe, Liberia....\n\n\n\nHow to use:\nGo to =\"\"http://www.MyPrepaidCenter.com/redeem\"\">MyPrepaidCenter.com/redeem and enter code\nComplete the online registration page and accept the cardholder agreement and e-sign agreement, then you will be able to view your 16-digit card number, expiration date, security information, where your card can be used, available balance, transaction history, etc.\nPlastic card available upon request. Requesting a plastic card will reduce the card’s value by $3.00 for manufacturing and fulfillment cost, and can take 7-14 business days. \nRecipient can request a plastic card once they have completed the card registration and activation at MyPrepaidCenter.com\"" }, - "country": { - "isoName": "US", - "name": "United States", - "flagUrl": "https://s3.amazonaws.com/rld-flags/us.svg" - }, - "redeemInstruction": { - "concise": "Your Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD", - "verbose": "Redeem Instruction:\nYour Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD\n\nTerms and condition:\nVirtual card is issued by Pathward®, N.A., Member FDIC, pursuant to license by Mastercard International Incorporated. Mastercard and the circles design are registered trademarks of Mastercard International Incorporated. No cash access or recurring payments. Can be used where Debit Mastercard is accepted online, for phone/mail orders, or in stores that accept mobile wallet. Valid for up to 6 months; unused funds will forfeit after the valid thru date. Terms and conditions apply. See Cardholder Agreement for details https://www.myprepaidcenter.com/page/mastercard-promo-virtual\n\nMastercard is widely accepted globally*, with the exception of certain countries where credit cards are blocked due to economic sanctions or other regulatory restrictions. Specifically, this includes:\nChina, The Democratic People's Republic of Korea (North Korea), The Islamic Republic of Iran, The Syrian Arab Republic, Ukraine, The Bahamas, Barbados, Benin, Burundi, Burkina Faso, Cambodia, The Cayman Islands, Chad, The Central African Republic, Congo, Comoros, Dominican Republic, Cuba, Guinea, Eritrea, Guinea-Bissau, Haiti, Iraq, Lebanon, Laos, Lesotho, Myanmar, Madagascar, Nicaragua, Panama, Somalia, Sudan, South Sudan, Uganda, Venezuela , Yemen, Zimbabwe, Liberia\n\nHow to use:\nGo to =\"http://www.MyPrepaidCenter.com/redeem\">MyPrepaidCenter.com/redeem and enter code\nComplete the online registration page and accept the cardholder agreement and e-sign agreement, then you will be able to view your 16-digit card number, expiration date, security information, where your card can be used, available balance, transaction history, etc.\nPlastic card available upon request. Requesting a plastic card will reduce the card’s value by $3.00 for manufacturing and fulfillment cost, and can take 7-14 business days. \nRecipient can request a plastic card once they have completed the card registration and activation at MyPrepaidCenter.com" + "additionalRequirements": { + "userIdRequired": false } }, { "productId": 18732, "productName": "Mastercard Prepaid USD Debit (Virtual only) US", "global": false, + "status": "ACTIVE", "supportsPreOrder": false, "senderFee": 1.0, "senderFeePercentage": 1.0, @@ -112,7 +79,10 @@ }, "redeemInstruction": { "concise": "Your Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD", - "verbose": "Redeem Instruction:\nYour Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD\n\nTerms and condition:\nVirtual card is issued by Pathward®, N.A., Member FDIC, pursuant to license by Mastercard International Incorporated. Mastercard and the circles design are registered trademarks of Mastercard International Incorporated. No cash access or recurring payments. Can be used where Debit Mastercard is accepted online, for phone/mail orders, or in stores that accept mobile wallet. Valid for up to 6 months; unused funds will forfeit after the valid thru date. Terms and conditions apply. See Cardholder Agreement for details https://www.myprepaidcenter.com/page/mastercard-promo-virtual\n\nMastercard is widely accepted globally*, with the exception of certain countries where credit cards are blocked due to economic sanctions or other regulatory restrictions. Specifically, this includes:\nChina, The Democratic People's Republic of Korea (North Korea), The Islamic Republic of Iran, The Syrian Arab Republic, Ukraine, The Bahamas, Barbados, Benin, Burundi, Burkina Faso, Cambodia, The Cayman Islands, Chad, The Central African Republic, Congo, Comoros, Dominican Republic, Cuba, Guinea, Eritrea, Guinea-Bissau, Haiti, Iraq, Lebanon, Laos, Lesotho, Myanmar, Madagascar, Nicaragua, Panama, Somalia, Sudan, South Sudan, Uganda, Venezuela , Yemen, Zimbabwe, Liberia\n\nHow to use:\nGo to =\"http://www.MyPrepaidCenter.com/redeem\">MyPrepaidCenter.com/redeem and enter code\nComplete the online registration page and accept the cardholder agreement and e-sign agreement, then you will be able to view your 16-digit card number, expiration date, security information, where your card can be used, available balance, transaction history, etc.\nPlastic card available upon request. Requesting a plastic card will reduce the card’s value by $3.00 for manufacturing and fulfillment cost, and can take 7-14 business days. \nRecipient can request a plastic card once they have completed the card registration and activation at MyPrepaidCenter.com" + "verbose": "Redeem Instruction:\nYour Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD\n\nTerms and condition:\nVirtual card is issued by Pathward®, N.A., Member FDIC, pursuant to license by Mastercard International Incorporated. Mastercard and the circles design are registered trademarks of Mastercard International Incorporated. No cash access or recurring payments. Can be used where Debit Mastercard is accepted online, for phone/mail orders, or in stores that accept mobile wallet. Valid for up to 6 months; unused funds will forfeit after the valid thru date. Terms and conditions apply. See Cardholder Agreement for details https://www.myprepaidcenter.com/page/mastercard-promo-virtual. A maximum of $9,500 can be purchased per 24 hours period\n\nMastercard is widely accepted globally*, with the exception of certain countries where credit cards are blocked due to economic sanctions or other regulatory restrictions. Specifically, this includes:\nChina, The Democratic People's Republic of Korea (North Korea), The Islamic Republic of Iran, The Syrian Arab Republic, Ukraine, The Bahamas, Barbados, Benin, Burundi, Burkina Faso, Cambodia, The Cayman Islands, Chad, The Central African Republic, Congo, Comoros, Dominican Republic, Cuba, Guinea, Eritrea, Guinea-Bissau, Haiti, Iraq, Lebanon, Laos, Lesotho, Myanmar, Madagascar, Nicaragua, Nigeria, Panama, Somalia, Sudan, South Sudan, Uganda, Venezuela , Yemen, Zimbabwe, Liberia\n\nHow to use:\nGo to =\"http://www.MyPrepaidCenter.com/redeem\">MyPrepaidCenter.com/redeem and enter code\nComplete the online registration page and accept the cardholder agreement and e-sign agreement, then you will be able to view your 16-digit card number, expiration date, security information, where your card can be used, available balance, transaction history, etc.\nPlastic card available upon request. Requesting a plastic card will reduce the card’s value by $3.00 for manufacturing and fulfillment cost, and can take 7-14 business days. \nRecipient can request a plastic card once they have completed the card registration and activation at MyPrepaidCenter.com\n\nCountries covered:\n\nAlgeria,American Samoa,Andorra,Angola,Anguilla,Antarctica,Antigua and Barbuda,Argentina,Armenia,Aruba,Australia,Austria,Azerbaijan,Bahrain,Bangladesh,Belgium,Belize,Bermuda,Bhutan,Bolivia,Botswana,Bouvet Island,Brazil,British Indian Ocean Territory,Brunei Darussalam,Bulgaria,Cabo Verde,Cameroon,Canada,Caribbean Netherlands,Chile,Christmas Island,Cocos (Keeling) Islands,Colombia,Cook Islands,Costa Rica,Croatia,Cura√ßao,Cyprus,Czech Republic,Denmark,Djibouti,Dominica,Ecuador,Egypt,El Salvador,Estonia,Falkland Islands,Faroe Islands,Federated States of Micronesia,Fiji,Finland,France,French Guiana,French Polynesia,French Southern Territories,Gabon,Gambia,Georgia,Germany,Ghana,Gibraltar,Greece,Greenland,Grenada,Guadeloupe,Guam,Guatemala,Guernsey,Guyana,Heard Island and McDonald Islands,Hong Kong,Hungary,Iceland,India,Indonesia,Ireland,Israel,Italy,Jamaica,Japan,Jersey,Jordan,Kazakhstan,Kenya,Kiribati,Latvia,Liechtenstein,Lithuania,Luxembourg,Malawi,Malaysia,Malta,Martinique,Mauritania,Mayotte,Mexico,Monaco,Montserrat,Morocco,Netherlands,New Zealand,Niger,Niue,Norfolk Island,Northern Mariana Islands,Norway,Oman,Palau,Peru,Philippines,Poland,Portugal,Puerto Rico,Qatar,Romania,Saudi Arabia,Singapore,Slovak Republic,Slovenia,Solomon Islands,South Africa,South Korea,Spain,Sri lanka,Sweden,Switzerland,Taiwan,Thailand,Tonga,Turkmenistan,Tuvalu,UAE,UK,Uruguay,USA,Vanuatu,Vatican City,Virgin Islands (U.S.)\n\nCountries Blocked:\n\nAfghanistan (AF),Albania (AL),Belarus (BY),Central African Republic (CF),Cuba (CU),China,Democratic Republic Of The Congo (CD),Eritrea (ER),Ethiopia (ET),Iran (Islamic Republic Of) (IR),Iraq (IQ),Kuwait,Lebanon (LB),Libyan Arab Jamahiriya (LY),Mali (ML),Myanmar (Burma) (MM),Montenegro,Nicaragua (NI),Nigeria,North Korea aka Democratic People’s Republic of Korea (KP),Russian Federation (RU),Somalia (SO),South Sudan (SS),Sudan (SD),Syrian Arab Republic (SY),Tunisia (TN),Turkey (TR),Ukraine (UA),Venezuela (VE),Vietnam,Yemen (YE),Zimbabwe (ZW)" + }, + "additionalRequirements": { + "userIdRequired": true } } ] diff --git a/tests/fixtures/get-best-card/card-18732.json b/tests/fixtures/get-best-card/card-18732.json new file mode 100644 index 00000000..08b94e05 --- /dev/null +++ b/tests/fixtures/get-best-card/card-18732.json @@ -0,0 +1,42 @@ +{ + "productId": 18732, + "productName": "Mastercard Prepaid USD Debit (Virtual only) US", + "global": false, + "status": "ACTIVE", + "supportsPreOrder": false, + "senderFee": 1.0, + "senderFeePercentage": 1.0, + "discountPercentage": 0.0, + "denominationType": "RANGE", + "recipientCurrencyCode": "USD", + "minRecipientDenomination": 5.0, + "maxRecipientDenomination": 1000.0, + "senderCurrencyCode": "USD", + "minSenderDenomination": 5.0, + "maxSenderDenomination": 1000.0, + "fixedRecipientDenominations": [], + "fixedSenderDenominations": null, + "fixedRecipientToSenderDenominationsMap": null, + "metadata": null, + "logoUrls": ["https://cdn.reloadly.com/giftcards/1e703d6a-b8a5-4b88-8f11-62cb3e4a5c0d.png"], + "brand": { + "brandId": 378, + "brandName": "Mastercard" + }, + "category": { + "id": 1, + "name": "Payment Cards" + }, + "country": { + "isoName": "US", + "name": "United States", + "flagUrl": "https://s3.amazonaws.com/rld-flags/us.svg" + }, + "redeemInstruction": { + "concise": "Your Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD", + "verbose": "Redeem Instruction:\nYour Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD\n\nTerms and condition:\nVirtual card is issued by Pathward®, N.A., Member FDIC, pursuant to license by Mastercard International Incorporated. Mastercard and the circles design are registered trademarks of Mastercard International Incorporated. No cash access or recurring payments. Can be used where Debit Mastercard is accepted online, for phone/mail orders, or in stores that accept mobile wallet. Valid for up to 6 months; unused funds will forfeit after the valid thru date. Terms and conditions apply. See Cardholder Agreement for details https://www.myprepaidcenter.com/page/mastercard-promo-virtual. A maximum of $9,500 can be purchased per 24 hours period\n\nMastercard is widely accepted globally*, with the exception of certain countries where credit cards are blocked due to economic sanctions or other regulatory restrictions. Specifically, this includes:\nChina, The Democratic People's Republic of Korea (North Korea), The Islamic Republic of Iran, The Syrian Arab Republic, Ukraine, The Bahamas, Barbados, Benin, Burundi, Burkina Faso, Cambodia, The Cayman Islands, Chad, The Central African Republic, Congo, Comoros, Dominican Republic, Cuba, Guinea, Eritrea, Guinea-Bissau, Haiti, Iraq, Lebanon, Laos, Lesotho, Myanmar, Madagascar, Nicaragua, Nigeria, Panama, Somalia, Sudan, South Sudan, Uganda, Venezuela , Yemen, Zimbabwe, Liberia\n\nHow to use:\nGo to =\"http://www.MyPrepaidCenter.com/redeem\">MyPrepaidCenter.com/redeem and enter code\nComplete the online registration page and accept the cardholder agreement and e-sign agreement, then you will be able to view your 16-digit card number, expiration date, security information, where your card can be used, available balance, transaction history, etc.\nPlastic card available upon request. Requesting a plastic card will reduce the card’s value by $3.00 for manufacturing and fulfillment cost, and can take 7-14 business days. \nRecipient can request a plastic card once they have completed the card registration and activation at MyPrepaidCenter.com\n\nCountries covered:\n\nAlgeria,American Samoa,Andorra,Angola,Anguilla,Antarctica,Antigua and Barbuda,Argentina,Armenia,Aruba,Australia,Austria,Azerbaijan,Bahrain,Bangladesh,Belgium,Belize,Bermuda,Bhutan,Bolivia,Botswana,Bouvet Island,Brazil,British Indian Ocean Territory,Brunei Darussalam,Bulgaria,Cabo Verde,Cameroon,Canada,Caribbean Netherlands,Chile,Christmas Island,Cocos (Keeling) Islands,Colombia,Cook Islands,Costa Rica,Croatia,Cura√ßao,Cyprus,Czech Republic,Denmark,Djibouti,Dominica,Ecuador,Egypt,El Salvador,Estonia,Falkland Islands,Faroe Islands,Federated States of Micronesia,Fiji,Finland,France,French Guiana,French Polynesia,French Southern Territories,Gabon,Gambia,Georgia,Germany,Ghana,Gibraltar,Greece,Greenland,Grenada,Guadeloupe,Guam,Guatemala,Guernsey,Guyana,Heard Island and McDonald Islands,Hong Kong,Hungary,Iceland,India,Indonesia,Ireland,Israel,Italy,Jamaica,Japan,Jersey,Jordan,Kazakhstan,Kenya,Kiribati,Latvia,Liechtenstein,Lithuania,Luxembourg,Malawi,Malaysia,Malta,Martinique,Mauritania,Mayotte,Mexico,Monaco,Montserrat,Morocco,Netherlands,New Zealand,Niger,Niue,Norfolk Island,Northern Mariana Islands,Norway,Oman,Palau,Peru,Philippines,Poland,Portugal,Puerto Rico,Qatar,Romania,Saudi Arabia,Singapore,Slovak Republic,Slovenia,Solomon Islands,South Africa,South Korea,Spain,Sri lanka,Sweden,Switzerland,Taiwan,Thailand,Tonga,Turkmenistan,Tuvalu,UAE,UK,Uruguay,USA,Vanuatu,Vatican City,Virgin Islands (U.S.)\n\nCountries Blocked:\n\nAfghanistan (AF),Albania (AL),Belarus (BY),Central African Republic (CF),Cuba (CU),China,Democratic Republic Of The Congo (CD),Eritrea (ER),Ethiopia (ET),Iran (Islamic Republic Of) (IR),Iraq (IQ),Kuwait,Lebanon (LB),Libyan Arab Jamahiriya (LY),Mali (ML),Myanmar (Burma) (MM),Montenegro,Nicaragua (NI),Nigeria,North Korea aka Democratic People’s Republic of Korea (KP),Russian Federation (RU),Somalia (SO),South Sudan (SS),Sudan (SD),Syrian Arab Republic (SY),Tunisia (TN),Turkey (TR),Ukraine (UA),Venezuela (VE),Vietnam,Yemen (YE),Zimbabwe (ZW)" + }, + "additionalRequirements": { + "userIdRequired": true + } +} diff --git a/tests/fixtures/http-mocks.ts b/tests/fixtures/http-mocks.ts index a5976a16..7f0a4cdb 100644 --- a/tests/fixtures/http-mocks.ts +++ b/tests/fixtures/http-mocks.ts @@ -7,7 +7,6 @@ import card18732 from "./post-order/card-18732.json"; import card18598 from "./get-best-card/card-18598.json"; import noCardMt from "./get-best-card/no-card-mt.json"; import transaction from "./get-order/transaction.json"; - import noTransaction from "./get-order/no-transaction.json"; import transaction0x33f4 from "./get-redeem-code/transaction-0x33f4.json"; import card from "./get-redeem-code/card.json"; @@ -22,6 +21,9 @@ export const httpMocks = [ http.post(RELOADLY_AUTH_URL, () => { return HttpResponse.json({ access_token: "fooBar" }); }), + http.get(`${RELOADLY_PRODUCTION_API_URL}/products/18732`, () => { + return HttpResponse.json(card18732, { status: 200 }); + }), http.get(`${RELOADLY_PRODUCTION_API_URL}/products/18597`, () => { return HttpResponse.json(card18597, { status: 200 }); }), diff --git a/tests/fixtures/post-order/card-18732.json b/tests/fixtures/post-order/card-18732.json index 0bcc744a..08b94e05 100644 --- a/tests/fixtures/post-order/card-18732.json +++ b/tests/fixtures/post-order/card-18732.json @@ -2,6 +2,7 @@ "productId": 18732, "productName": "Mastercard Prepaid USD Debit (Virtual only) US", "global": false, + "status": "ACTIVE", "supportsPreOrder": false, "senderFee": 1.0, "senderFeePercentage": 1.0, @@ -33,6 +34,9 @@ }, "redeemInstruction": { "concise": "Your Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD", - "verbose": "Redeem Instruction:\nYour Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD\n\nTerms and condition:\nVirtual card is issued by Pathward®, N.A., Member FDIC, pursuant to license by Mastercard International Incorporated. Mastercard and the circles design are registered trademarks of Mastercard International Incorporated. No cash access or recurring payments. Can be used where Debit Mastercard is accepted online, for phone/mail orders, or in stores that accept mobile wallet. Valid for up to 6 months; unused funds will forfeit after the valid thru date. Terms and conditions apply. See Cardholder Agreement for details https://www.myprepaidcenter.com/page/mastercard-promo-virtual\n\nMastercard is widely accepted globally*, with the exception of certain countries where credit cards are blocked due to economic sanctions or other regulatory restrictions. Specifically, this includes:\nChina, The Democratic People's Republic of Korea (North Korea), The Islamic Republic of Iran, The Syrian Arab Republic, Ukraine, The Bahamas, Barbados, Benin, Burundi, Burkina Faso, Cambodia, The Cayman Islands, Chad, The Central African Republic, Congo, Comoros, Dominican Republic, Cuba, Guinea, Eritrea, Guinea-Bissau, Haiti, Iraq, Lebanon, Laos, Lesotho, Myanmar, Madagascar, Nicaragua, Panama, Somalia, Sudan, South Sudan, Uganda, Venezuela , Yemen, Zimbabwe, Liberia\n\nHow to use:\nGo to =\"http://www.MyPrepaidCenter.com/redeem\">MyPrepaidCenter.com/redeem and enter code\nComplete the online registration page and accept the cardholder agreement and e-sign agreement, then you will be able to view your 16-digit card number, expiration date, security information, where your card can be used, available balance, transaction history, etc.\nPlastic card available upon request. Requesting a plastic card will reduce the card’s value by $3.00 for manufacturing and fulfillment cost, and can take 7-14 business days. \nRecipient can request a plastic card once they have completed the card registration and activation at MyPrepaidCenter.com" + "verbose": "Redeem Instruction:\nYour Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD\n\nTerms and condition:\nVirtual card is issued by Pathward®, N.A., Member FDIC, pursuant to license by Mastercard International Incorporated. Mastercard and the circles design are registered trademarks of Mastercard International Incorporated. No cash access or recurring payments. Can be used where Debit Mastercard is accepted online, for phone/mail orders, or in stores that accept mobile wallet. Valid for up to 6 months; unused funds will forfeit after the valid thru date. Terms and conditions apply. See Cardholder Agreement for details https://www.myprepaidcenter.com/page/mastercard-promo-virtual. A maximum of $9,500 can be purchased per 24 hours period\n\nMastercard is widely accepted globally*, with the exception of certain countries where credit cards are blocked due to economic sanctions or other regulatory restrictions. Specifically, this includes:\nChina, The Democratic People's Republic of Korea (North Korea), The Islamic Republic of Iran, The Syrian Arab Republic, Ukraine, The Bahamas, Barbados, Benin, Burundi, Burkina Faso, Cambodia, The Cayman Islands, Chad, The Central African Republic, Congo, Comoros, Dominican Republic, Cuba, Guinea, Eritrea, Guinea-Bissau, Haiti, Iraq, Lebanon, Laos, Lesotho, Myanmar, Madagascar, Nicaragua, Nigeria, Panama, Somalia, Sudan, South Sudan, Uganda, Venezuela , Yemen, Zimbabwe, Liberia\n\nHow to use:\nGo to =\"http://www.MyPrepaidCenter.com/redeem\">MyPrepaidCenter.com/redeem and enter code\nComplete the online registration page and accept the cardholder agreement and e-sign agreement, then you will be able to view your 16-digit card number, expiration date, security information, where your card can be used, available balance, transaction history, etc.\nPlastic card available upon request. Requesting a plastic card will reduce the card’s value by $3.00 for manufacturing and fulfillment cost, and can take 7-14 business days. \nRecipient can request a plastic card once they have completed the card registration and activation at MyPrepaidCenter.com\n\nCountries covered:\n\nAlgeria,American Samoa,Andorra,Angola,Anguilla,Antarctica,Antigua and Barbuda,Argentina,Armenia,Aruba,Australia,Austria,Azerbaijan,Bahrain,Bangladesh,Belgium,Belize,Bermuda,Bhutan,Bolivia,Botswana,Bouvet Island,Brazil,British Indian Ocean Territory,Brunei Darussalam,Bulgaria,Cabo Verde,Cameroon,Canada,Caribbean Netherlands,Chile,Christmas Island,Cocos (Keeling) Islands,Colombia,Cook Islands,Costa Rica,Croatia,Cura√ßao,Cyprus,Czech Republic,Denmark,Djibouti,Dominica,Ecuador,Egypt,El Salvador,Estonia,Falkland Islands,Faroe Islands,Federated States of Micronesia,Fiji,Finland,France,French Guiana,French Polynesia,French Southern Territories,Gabon,Gambia,Georgia,Germany,Ghana,Gibraltar,Greece,Greenland,Grenada,Guadeloupe,Guam,Guatemala,Guernsey,Guyana,Heard Island and McDonald Islands,Hong Kong,Hungary,Iceland,India,Indonesia,Ireland,Israel,Italy,Jamaica,Japan,Jersey,Jordan,Kazakhstan,Kenya,Kiribati,Latvia,Liechtenstein,Lithuania,Luxembourg,Malawi,Malaysia,Malta,Martinique,Mauritania,Mayotte,Mexico,Monaco,Montserrat,Morocco,Netherlands,New Zealand,Niger,Niue,Norfolk Island,Northern Mariana Islands,Norway,Oman,Palau,Peru,Philippines,Poland,Portugal,Puerto Rico,Qatar,Romania,Saudi Arabia,Singapore,Slovak Republic,Slovenia,Solomon Islands,South Africa,South Korea,Spain,Sri lanka,Sweden,Switzerland,Taiwan,Thailand,Tonga,Turkmenistan,Tuvalu,UAE,UK,Uruguay,USA,Vanuatu,Vatican City,Virgin Islands (U.S.)\n\nCountries Blocked:\n\nAfghanistan (AF),Albania (AL),Belarus (BY),Central African Republic (CF),Cuba (CU),China,Democratic Republic Of The Congo (CD),Eritrea (ER),Ethiopia (ET),Iran (Islamic Republic Of) (IR),Iraq (IQ),Kuwait,Lebanon (LB),Libyan Arab Jamahiriya (LY),Mali (ML),Myanmar (Burma) (MM),Montenegro,Nicaragua (NI),Nigeria,North Korea aka Democratic People’s Republic of Korea (KP),Russian Federation (RU),Somalia (SO),South Sudan (SS),Sudan (SD),Syrian Arab Republic (SY),Tunisia (TN),Turkey (TR),Ukraine (UA),Venezuela (VE),Vietnam,Yemen (YE),Zimbabwe (ZW)" + }, + "additionalRequirements": { + "userIdRequired": true } } diff --git a/tests/unit/get-best-card.test.ts b/tests/unit/get-best-card.test.ts index eea11a08..d29c8686 100644 --- a/tests/unit/get-best-card.test.ts +++ b/tests/unit/get-best-card.test.ts @@ -4,7 +4,7 @@ import { setupServer, SetupServerApi } from "msw/node"; import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest"; import { onRequest as pagesFunction } from "../../functions/get-best-card"; import bestCard from "../fixtures/get-best-card/best-card-sandbox.json"; -import card18597 from "../fixtures/get-best-card/card-18597.json"; +import card18732 from "../fixtures/get-best-card/card-18732.json"; import { httpMocks } from "../fixtures/http-mocks"; import { createEventContext, TESTS_BASE_URL } from "./shared-utils"; @@ -36,7 +36,7 @@ describe("Get best payment card", () => { const response = await pagesFunction(eventCtx); await waitOnExecutionContext(execContext); expect(response.status).toBe(200); - expect(await response.json()).toEqual(card18597); + expect(await response.json()).toEqual(card18732); }); it("should respond with US International Mastercard for Malta as fallback", async () => { @@ -45,7 +45,7 @@ describe("Get best payment card", () => { const response = await pagesFunction(eventCtx); await waitOnExecutionContext(execContext); expect(response.status).toBe(200); - expect(await response.json()).toEqual(card18597); + expect(await response.json()).toEqual(card18732); }); it("should respond with no payment card for unsupported country", async () => { From 4d78bc32bd239a011c7a9ddf865820490392c20a Mon Sep 17 00:00:00 2001 From: EresDev Date: Wed, 11 Dec 2024 15:57:46 +0500 Subject: [PATCH 04/15] test: fix broken test for /post-order with sku 18732 --- tests/fixtures/http-mocks.ts | 4 +-- .../fixtures/post-order/order-card-18732.json | 36 +++++++++++++++++++ tests/unit/post-order.test.ts | 16 ++++----- 3 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 tests/fixtures/post-order/order-card-18732.json diff --git a/tests/fixtures/http-mocks.ts b/tests/fixtures/http-mocks.ts index 7f0a4cdb..33aaba3a 100644 --- a/tests/fixtures/http-mocks.ts +++ b/tests/fixtures/http-mocks.ts @@ -11,7 +11,7 @@ import noTransaction from "./get-order/no-transaction.json"; import transaction0x33f4 from "./get-redeem-code/transaction-0x33f4.json"; import card from "./get-redeem-code/card.json"; import orderCard13959 from "./post-order/order-card-13959.json"; -import orderCard18597 from "./post-order/order-card-18597.json"; +import orderCard18732 from "./post-order/order-card-18732.json"; import { RELOADLY_AUTH_URL, RELOADLY_PRODUCTION_API_URL, RELOADLY_SANDBOX_API_URL } from "../../functions/utils/shared"; /** @@ -73,7 +73,7 @@ export const httpMocks = [ }), http.post(`${RELOADLY_PRODUCTION_API_URL}/orders`, () => { - return HttpResponse.json(orderCard18597, { status: 200 }); + return HttpResponse.json(orderCard18732, { status: 200 }); }), http.post(`${RELOADLY_SANDBOX_API_URL}/orders`, () => { return HttpResponse.json(orderCard13959, { status: 200 }); diff --git a/tests/fixtures/post-order/order-card-18732.json b/tests/fixtures/post-order/order-card-18732.json new file mode 100644 index 00000000..8abe901c --- /dev/null +++ b/tests/fixtures/post-order/order-card-18732.json @@ -0,0 +1,36 @@ +{ + "transactionId": 39018, + "amount": 50, + "discount": 0, + "currencyCode": "USD", + "fee": 6, + "smsFee": 0, + "totalFee": 6, + "preOrdered": false, + "recipientEmail": null, + "recipientPhone": null, + "customIdentifier": "0xd670e1f4f47a0104217f30a8804f7e13803da1dbfd9270dcb6d8d3a5ba72a52e", + "status": "SUCCESSFUL", + "transactionCreatedTime": "2024-11-03 03:25:42", + "product": { + "productId": 18732, + "productName": "Mastercard Prepaid USD Debit (Virtual only) US", + "countryCode": "US", + "quantity": 1, + "unitPrice": 44, + "totalPrice": 44, + "currencyCode": "USD", + "brand": { + "brandId": 378, + "brandName": "Mastercard" + } + }, + "balanceInfo": { + "oldBalance": 212439823.44865, + "newBalance": 212439773.44865, + "cost": 50, + "currencyCode": "USD", + "currencyName": "US Dollar", + "updatedAt": "2024-11-02 13:46:17" + } +} diff --git a/tests/unit/post-order.test.ts b/tests/unit/post-order.test.ts index 32a75c3b..97422a86 100644 --- a/tests/unit/post-order.test.ts +++ b/tests/unit/post-order.test.ts @@ -13,7 +13,7 @@ import minedTxTooLow from "../fixtures/post-order/mined-tx-too-low.json"; import minedTxUusd from "../fixtures/post-order/mined-tx-uusd.json"; import minedTxGeneric from "../fixtures/post-order/mined-tx.json"; import orderCard13959 from "../fixtures/post-order/order-card-13959.json"; -import orderCard18597 from "../fixtures/post-order/order-card-18597.json"; +import orderCard18732 from "../fixtures/post-order/order-card-18732.json"; import parsedTxUusdWrongMethod from "../fixtures/post-order/parsed-tx-uusd-wrong-method.json"; import parsedTxUusdWrongTreasury from "../fixtures/post-order/parsed-tx-uusd-wrong-treasury.json"; import parsedTxWrongMethod from "../fixtures/post-order/parsed-tx-wrong-method.json"; @@ -66,17 +66,17 @@ describe("Post order for a payment card", () => { type: "permit", chainId: 31337, txHash: "0xac3485ce523faa13970412a89ef42d10939b44abd33cbcff1ed84cb566a3a3d5", - productId: 18597, + productId: 18732, country: "US", - signedMessage: "0x054114b71b08d0dbe6639a4810169a45591c96ebbba94f7540e1696499dd179418fe58c6e254fe84a99d19a04a502eefc990f88f8352a528f70cd54fe3a71a0b1c", + signedMessage: "0xab1c86111f7f5062ac0c0d44e7008c20cd92f3455aaf026ca0a53838a3dfa4b77e088ae5faa0ee0ceab31340986dcd9cb031001e5d730f730c52c1c4cfb3de0a1b", }), }) as Request>; const eventCtx = createEventContext(request, execContext); const response = await pagesFunction(eventCtx); await waitOnExecutionContext(execContext); + expect(await response.json()).toEqual(orderCard18732); expect(response.status).toBe(200); - expect(await response.json()).toEqual(orderCard18597); }); it("should return err for ordering card that is not best suited", async () => { @@ -87,9 +87,9 @@ describe("Post order for a payment card", () => { type: "permit", chainId: 31337, txHash: "0xac3485ce523faa13970412a89ef42d10939b44abd33cbcff1ed84cb566a3a3d5", - productId: 18732, + productId: 18597, country: "US", - signedMessage: "0xab1c86111f7f5062ac0c0d44e7008c20cd92f3455aaf026ca0a53838a3dfa4b77e088ae5faa0ee0ceab31340986dcd9cb031001e5d730f730c52c1c4cfb3de0a1b", + signedMessage: "0x054114b71b08d0dbe6639a4810169a45591c96ebbba94f7540e1696499dd179418fe58c6e254fe84a99d19a04a502eefc990f88f8352a528f70cd54fe3a71a0b1c", }), }) as Request>; @@ -342,7 +342,7 @@ describe("Post order for a payment card", () => { type: uusd, chainId: 31337, txHash: "0xdf1bf8b6d679e406f43b57692a2dcbb450e38d5de72e5199d836b701d0a4306f", - productId: 18597, + productId: 18732, country: "US", }), }) as Request>; @@ -351,7 +351,7 @@ describe("Post order for a payment card", () => { const response = await pagesFunction(eventCtx); await waitOnExecutionContext(execContext); expect(response.status).toBe(200); - expect(await response.json()).toEqual(orderCard18597); + expect(await response.json()).toEqual(orderCard18732); }); it("should return err with uusd for unsupported chain", async () => { From 40af4492dd607ff7eebbd7956eb761696dfebcac Mon Sep 17 00:00:00 2001 From: EresDev Date: Wed, 11 Dec 2024 16:10:43 +0500 Subject: [PATCH 05/15] fix: add new sku 18732 to intl cards list --- functions/utils/reloadly-lists.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/functions/utils/reloadly-lists.ts b/functions/utils/reloadly-lists.ts index d5ad8e25..f7855d09 100644 --- a/functions/utils/reloadly-lists.ts +++ b/functions/utils/reloadly-lists.ts @@ -23,6 +23,12 @@ export const fallbackIntlVisa = { }; export const masterCardIntlSkus = [ + { + country: "United States", + countryCode: "US", + name: "Mastercard Prepaid USD Debit (Virtual only) US", + sku: 18732, + }, { country: "United States", countryCode: "US", From 69e0880de4c88607c75caa9305ecb0c8c2c9e87e Mon Sep 17 00:00:00 2001 From: EresDev Date: Wed, 11 Dec 2024 16:42:14 +0500 Subject: [PATCH 06/15] fix: consider new & old both intl fallback mastercards --- functions/utils/best-card-finder.ts | 28 +++++++++++++++++++++------- functions/utils/reloadly-lists.ts | 4 ++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/functions/utils/best-card-finder.ts b/functions/utils/best-card-finder.ts index 492fc4b4..2db37a08 100644 --- a/functions/utils/best-card-finder.ts +++ b/functions/utils/best-card-finder.ts @@ -4,7 +4,7 @@ import { isGiftCardAvailable } from "../../shared/helpers"; import { GiftCard } from "../../shared/types"; import { commonHeaders, getGiftCards, getReloadlyApiBaseUrl } from "./shared"; import { getGiftCardById } from "../post-order"; -import { fallbackIntlMastercard, fallbackIntlVisa, masterCardIntlSkus, visaIntlSkus } from "./reloadly-lists"; +import { fallbackIntlMastercardFirst, fallbackIntlMastercardSecond, fallbackIntlVisa, masterCardIntlSkus, visaIntlSkus } from "./reloadly-lists"; import { AccessToken, ReloadlyFailureResponse } from "./types"; export async function findBestCard(countryCode: string, amount: BigNumberish, accessToken: AccessToken): Promise { @@ -55,9 +55,14 @@ async function findBestMastercard(masterCards: GiftCard[], countryCode: string, } } - const fallbackMastercard = await getFallbackIntlMastercard(accessToken); - if (fallbackMastercard && isGiftCardAvailable(fallbackMastercard, amount)) { - return fallbackMastercard; + const fallbackMastercardFirst = await getFirstFallbackIntlMastercard(accessToken); + if (fallbackMastercardFirst && isGiftCardAvailable(fallbackMastercardFirst, amount)) { + return fallbackMastercardFirst; + } + + const fallbackMastercardSecond = await getSecondFallbackIntlMastercard(accessToken); + if (fallbackMastercardSecond && isGiftCardAvailable(fallbackMastercardSecond, amount)) { + return fallbackMastercardSecond; } return null; @@ -78,11 +83,20 @@ async function findBestVisaCard(visaCards: GiftCard[], countryCode: string, amou } return null; } -async function getFallbackIntlMastercard(accessToken: AccessToken): Promise { +async function getFirstFallbackIntlMastercard(accessToken: AccessToken): Promise { + try { + return await getGiftCardById(fallbackIntlMastercardFirst.sku, accessToken); + } catch (e) { + console.error(`Failed to load international US mastercard: ${JSON.stringify(fallbackIntlMastercardFirst)}`, e); + return null; + } +} + +async function getSecondFallbackIntlMastercard(accessToken: AccessToken): Promise { try { - return await getGiftCardById(fallbackIntlMastercard.sku, accessToken); + return await getGiftCardById(fallbackIntlMastercardSecond.sku, accessToken); } catch (e) { - console.error(`Failed to load international US mastercard: ${JSON.stringify(fallbackIntlMastercard)}`, e); + console.error(`Failed to load international US mastercard: ${JSON.stringify(fallbackIntlMastercardSecond)}`, e); return null; } } diff --git a/functions/utils/reloadly-lists.ts b/functions/utils/reloadly-lists.ts index f7855d09..c88b259d 100644 --- a/functions/utils/reloadly-lists.ts +++ b/functions/utils/reloadly-lists.ts @@ -1,14 +1,14 @@ /* eslint-disable sonarjs/no-duplicate-string */ // Keep duplicate country names in different lists -export const fallbackIntlMastercard = { +export const fallbackIntlMastercardFirst = { country: "United States", countryCode: "US", name: "Mastercard Prepaid USD Debit (Virtual only) US", sku: 18732, }; -export const fallbackIntlMastercardOld = { +export const fallbackIntlMastercardSecond = { country: "United States", countryCode: "US", name: "Virtual MasterCard International USD US", From 93b31c81f1f7137e17ce93dd60da6a5f7cb830f7 Mon Sep 17 00:00:00 2001 From: EresDev Date: Wed, 11 Dec 2024 22:49:52 +0500 Subject: [PATCH 07/15] test: offer second fallback mastercard --- functions/utils/best-card-finder.ts | 4 +-- .../get-best-card/card-18732-not-found.json | 8 +++++ tests/fixtures/get-best-card/no-card-kr.json | 8 +++++ tests/unit/get-best-card.test.ts | 32 +++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/get-best-card/card-18732-not-found.json create mode 100644 tests/fixtures/get-best-card/no-card-kr.json diff --git a/functions/utils/best-card-finder.ts b/functions/utils/best-card-finder.ts index 2db37a08..bd59ae0a 100644 --- a/functions/utils/best-card-finder.ts +++ b/functions/utils/best-card-finder.ts @@ -87,7 +87,7 @@ async function getFirstFallbackIntlMastercard(accessToken: AccessToken): Promise try { return await getGiftCardById(fallbackIntlMastercardFirst.sku, accessToken); } catch (e) { - console.error(`Failed to load international US mastercard: ${JSON.stringify(fallbackIntlMastercardFirst)}`, e); + console.error(`Failed to load first fallback mastercard: ${JSON.stringify(fallbackIntlMastercardFirst)}`, e); return null; } } @@ -96,7 +96,7 @@ async function getSecondFallbackIntlMastercard(accessToken: AccessToken): Promis try { return await getGiftCardById(fallbackIntlMastercardSecond.sku, accessToken); } catch (e) { - console.error(`Failed to load international US mastercard: ${JSON.stringify(fallbackIntlMastercardSecond)}`, e); + console.error(`Failed to load second fallback mastercard: ${JSON.stringify(fallbackIntlMastercardSecond)}`, e); return null; } } diff --git a/tests/fixtures/get-best-card/card-18732-not-found.json b/tests/fixtures/get-best-card/card-18732-not-found.json new file mode 100644 index 00000000..0dfa848c --- /dev/null +++ b/tests/fixtures/get-best-card/card-18732-not-found.json @@ -0,0 +1,8 @@ +{ + "timeStamp": "2024-12-11 17:23:46", + "message": "The product was either not found or is no longer available, Please contact support", + "path": "/products/18732", + "errorCode": "PRODUCT_NOT_FOUND", + "infoLink": null, + "details": [] +} diff --git a/tests/fixtures/get-best-card/no-card-kr.json b/tests/fixtures/get-best-card/no-card-kr.json new file mode 100644 index 00000000..448e5ff1 --- /dev/null +++ b/tests/fixtures/get-best-card/no-card-kr.json @@ -0,0 +1,8 @@ +{ + "timeStamp": "2024-12-11 16:32:37", + "message": "No products were found for the given country code. For a list of valid country codes visit https://www.nationsonline.org/oneworld/country_code_list.htm", + "path": "/countries/KR/products", + "errorCode": null, + "infoLink": null, + "details": [] +} diff --git a/tests/unit/get-best-card.test.ts b/tests/unit/get-best-card.test.ts index d29c8686..96513215 100644 --- a/tests/unit/get-best-card.test.ts +++ b/tests/unit/get-best-card.test.ts @@ -1,10 +1,15 @@ import { parseEther } from "@ethersproject/units"; import { createExecutionContext, waitOnExecutionContext } from "cloudflare:test"; +import { http, HttpResponse } from "msw"; import { setupServer, SetupServerApi } from "msw/node"; import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest"; import { onRequest as pagesFunction } from "../../functions/get-best-card"; +import { RELOADLY_PRODUCTION_API_URL } from "../../functions/utils/shared"; import bestCard from "../fixtures/get-best-card/best-card-sandbox.json"; +import card18597 from "../fixtures/get-best-card/card-18597.json"; import card18732 from "../fixtures/get-best-card/card-18732.json"; +import card18732NotFound from "../fixtures/get-best-card/card-18732-not-found.json"; +import noCardKr from "../fixtures/get-best-card/no-card-kr.json"; import { httpMocks } from "../fixtures/http-mocks"; import { createEventContext, TESTS_BASE_URL } from "./shared-utils"; @@ -66,6 +71,33 @@ describe("Get best payment card", () => { expect(await response.json()).toEqual({ message: "There are no gift cards available." }); }); + it("should respond with fallbackMastercardSecond when other cards are unavailable", async () => { + try { + server.use( + ...[ + http.get(`${RELOADLY_PRODUCTION_API_URL}/countries/KR/products`, () => { + return HttpResponse.json(noCardKr, { status: 404 }); + }), + http.get(`${RELOADLY_PRODUCTION_API_URL}/products/18732`, () => { + return HttpResponse.json(card18732NotFound, { status: 404 }); + }), + http.get(`${RELOADLY_PRODUCTION_API_URL}/products/18597`, () => { + return HttpResponse.json(card18597, { status: 200 }); + }), + ] + ); + } catch (e) { + console.log(`Error starting msw server: ${e}`); + } + + const request = new Request(`${TESTS_BASE_URL}/get-best-card?country=KR&amount=${parseEther("50")}`); + const eventCtx = createEventContext(request, execContext); + const response = await pagesFunction(eventCtx); + await waitOnExecutionContext(execContext); + expect(await response.json()).toEqual(card18597); + expect(response.status).toBe(200); + }); + it("should respond with correct payment card for sandbox", async () => { const request = new Request(`${TESTS_BASE_URL}/get-best-card?country=US&amount=${parseEther("50")}`); const eventCtx = createEventContext(request, execContext, true); From 891630ab2d2cdaf046656349dbeaadbc6b4da5e8 Mon Sep 17 00:00:00 2001 From: EresDev Date: Thu, 12 Dec 2024 16:05:33 +0900 Subject: [PATCH 08/15] fix: use UUSD as reward token for chain 100 --- shared/constants.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shared/constants.ts b/shared/constants.ts index d783281a..6f88ee07 100644 --- a/shared/constants.ts +++ b/shared/constants.ts @@ -1,6 +1,7 @@ export enum Tokens { DAI = "0x6b175474e89094c44da98b954eedeac495271d0f", WXDAI = "0xe91d153e0b41518a2ce8dd3d7944fa863463a97d", + UUSD = "0xC6ed4f520f6A4e4DC27273509239b7F8A68d2068", } export const permitAllowedChainIds = [1, 5, 10, 100, 31337]; @@ -18,8 +19,8 @@ export const ubiquityDollarChainAddresses: Record = { export const chainIdToRewardTokenMap: Record = { 1: Tokens.DAI, - 100: Tokens.WXDAI, - 31337: Tokens.WXDAI, + 100: Tokens.UUSD, + 31337: Tokens.UUSD, }; export const chainIdToNameMap: Record = { From d06e7f68258408eed4a8100ea538cc428bd0c9ce Mon Sep 17 00:00:00 2001 From: EresDev Date: Thu, 12 Dec 2024 16:06:08 +0900 Subject: [PATCH 09/15] fix: use UUSD in local anvil fork for reward --- cypress/scripts/funding.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cypress/scripts/funding.ts b/cypress/scripts/funding.ts index 0144607d..accc8615 100644 --- a/cypress/scripts/funding.ts +++ b/cypress/scripts/funding.ts @@ -1,5 +1,6 @@ /* eslint-disable sonarjs/no-duplicate-string */ import { SpawnSyncOptionsWithStringEncoding, spawnSync } from "child_process"; +import { chainIdToRewardTokenMap } from "../../shared/constants"; /** * Handles the async funding of the testing environment @@ -16,11 +17,11 @@ class TestFunder { fundingWallet = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"; beneficiary = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; permit2 = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; - WXDAI = "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d"; - whale = "0xba12222222228d8ba445958a75a0704d566bf2c8"; + rewardToken = chainIdToRewardTokenMap[100]; + whale = "0xefC0e701A824943b469a694aC564Aa1efF7Ab7dd"; expected = { allowance: "999999999999999111119999999999999999", - balance: "337888400000000000000000", + balance: "10000000000000000000000", }; async execute() { @@ -117,7 +118,7 @@ class TestFunder { private async _fundingAllowanceCheck() { const allowance = await this._exec({ command: "cast", - args: ["call", this.WXDAI, "allowance(address,address)(uint256)", this.fundingWallet, this.permit2, "--rpc-url", this.anvilRPC], + args: ["call", this.rewardToken, "allowance(address,address)(uint256)", this.fundingWallet, this.permit2, "--rpc-url", this.anvilRPC], options: { encoding: "utf8" }, }); @@ -127,7 +128,7 @@ class TestFunder { private async _fundingBalanceCheck() { const balance = await this._exec({ command: "cast", - args: ["call", this.WXDAI, "balanceOf(address)(uint256)", this.fundingWallet, "--rpc-url", this.anvilRPC], + args: ["call", this.rewardToken, "balanceOf(address)(uint256)", this.fundingWallet, "--rpc-url", this.anvilRPC], options: { encoding: "utf8" }, }); @@ -141,7 +142,7 @@ class TestFunder { "send", "--rpc-url", this.anvilRPC, - this.WXDAI, + this.rewardToken, "--unlocked", "--from", address, @@ -173,7 +174,7 @@ class TestFunder { "send", "--rpc-url", this.anvilRPC, - this.WXDAI, + this.rewardToken, "--unlocked", "--from", this.whale, @@ -200,7 +201,7 @@ class TestFunder { "send", "--rpc-url", this.anvilRPC, - this.WXDAI, + this.rewardToken, "--unlocked", "--from", this.fundingWallet, From 83b56413991a4ebacf4929fae4529f35b7573e51 Mon Sep 17 00:00:00 2001 From: EresDev Date: Thu, 12 Dec 2024 16:07:47 +0900 Subject: [PATCH 10/15] test: use WXDAI as reward token in tests as in fixtures --- tests/unit/post-order.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/unit/post-order.test.ts b/tests/unit/post-order.test.ts index 97422a86..9080077e 100644 --- a/tests/unit/post-order.test.ts +++ b/tests/unit/post-order.test.ts @@ -27,6 +27,7 @@ import receiptTxForMockedParse from "../fixtures/post-order/receipt-tx-for-mocke import receiptUusd from "../fixtures/post-order/receipt-tx-uusd.json"; import receiptGeneric from "../fixtures/post-order/receipt.json"; import { createEventContext, TESTS_BASE_URL } from "./shared-utils"; +import * as constant from "../../shared/constants"; describe("Post order for a payment card", () => { let server: SetupServerApi; @@ -43,6 +44,8 @@ describe("Post order for a payment card", () => { } catch (e) { console.log(`Error starting msw server: ${e}`); } + // Fixture use wxdai token for reward + constant.chainIdToRewardTokenMap[31337] = constant.Tokens.WXDAI; }); beforeEach(async () => { @@ -430,8 +433,9 @@ describe("Post order for a payment card", () => { const eventCtx = createEventContext(request, execContext, true); const response = await pagesFunction(eventCtx); await waitOnExecutionContext(execContext); - expect(response.status).toBe(200); + expect(await response.json()).toEqual(orderCard13959); + expect(response.status).toBe(200); }); it("should post order on sandbox", async () => { @@ -451,8 +455,9 @@ describe("Post order for a payment card", () => { const eventCtx = createEventContext(request, execContext, true); const response = await pagesFunction(eventCtx); await waitOnExecutionContext(execContext); - expect(response.status).toBe(200); + expect(await response.json()).toEqual(orderCard13959); + expect(response.status).toBe(200); }); }); From fd4d4a5489ecced51d7e661cde554060937a6eed Mon Sep 17 00:00:00 2001 From: EresDev Date: Thu, 12 Dec 2024 16:19:08 +0900 Subject: [PATCH 11/15] feat: show card sku in UI will help with troubleshooting exact card if mint fails --- static/scripts/rewards/gift-cards/gift-card.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/static/scripts/rewards/gift-cards/gift-card.ts b/static/scripts/rewards/gift-cards/gift-card.ts index 01fb4c04..78fabb88 100644 --- a/static/scripts/rewards/gift-cards/gift-card.ts +++ b/static/scripts/rewards/gift-cards/gift-card.ts @@ -14,9 +14,11 @@ export function getGiftCardHtml(giftCard: GiftCard, rewardAmount: BigNumberish)

${giftCard.productName}

+
${giftCard.denominationType == "FIXED" ? getFixedPricesHtml(giftCard, rewardAmount) : getRangePricesHtml(giftCard, rewardAmount)}
+
SKU: ${giftCard.productId}