From 7083131cf787c5cc6c8c031c25619c559b16afba Mon Sep 17 00:00:00 2001 From: Danilo Cardoso Date: Thu, 24 Oct 2024 15:25:15 +0200 Subject: [PATCH 1/3] feat: logic for the PBL details link storage --- .../main/default/classes/AdyenPBLHelper.cls | 24 ++++++++++++------- .../default/classes/AdyenPaymentHelper.cls | 8 +++++++ .../classes/AdyenPaymentHelperTest.cls | 3 ++- .../AdyenPaymentHelperTest.cls-meta.xml | 2 +- .../main/default/classes/TestDataFactory.cls | 2 +- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/force-app/main/default/classes/AdyenPBLHelper.cls b/force-app/main/default/classes/AdyenPBLHelper.cls index 0d18b87..59a3374 100644 --- a/force-app/main/default/classes/AdyenPBLHelper.cls +++ b/force-app/main/default/classes/AdyenPBLHelper.cls @@ -60,15 +60,23 @@ public with sharing class AdyenPBLHelper { private static String getLinkExpiryDate(Integer days) { Datetime currentDateTime = Datetime.now(); Datetime expiryDateTime = currentDateTime.addDays(days); - - return formatDateTimeToISO8601(expiryDateTime); + return expiryDateTime.format('yyyy-MM-dd\'T\'HH:mm:ssXXX'); } - private static String formatDateTimeToISO8601(Datetime dt) { - String iso8601Date = dt.formatGmt('yyyy-MM-dd\'T\'HH:mm:ss'); - String timeZoneOffset = Datetime.now().format('Z'); - String formattedOffset = timeZoneOffset.substring(0, 3) + ':' + timeZoneOffset.substring(3); + public static Datetime parseDateTime(String dateTimeStr) { + String[] parts = dateTimeStr.split('\\+'); + String dateTimePart = parts[0]; // example: '2024-10-25T09:38:49' + String timeZoneOffset = parts[1]; // example: '02:00' + + dateTimePart = dateTimePart.replace('T', ' '); + Datetime dt = Datetime.valueOf(dateTimePart); + + Integer offsetHours = Integer.valueOf(timeZoneOffset.substring(0, 2)); + Integer offsetMinutes = Integer.valueOf(timeZoneOffset.substring(3, 5)); + // Adjust DateTime by subtracting the offset to store it as UTC + dt = dt.addHours(-offsetHours); + dt = dt.addMinutes(-offsetMinutes); - return iso8601Date + formattedOffset; + return dt; } -} \ No newline at end of file +} diff --git a/force-app/main/default/classes/AdyenPaymentHelper.cls b/force-app/main/default/classes/AdyenPaymentHelper.cls index 96c8c86..c607a1f 100644 --- a/force-app/main/default/classes/AdyenPaymentHelper.cls +++ b/force-app/main/default/classes/AdyenPaymentHelper.cls @@ -166,6 +166,8 @@ public with sharing class AdyenPaymentHelper { postAuthResponse.paymentGroupId = postAuthorizationResponse.paymentGroup.id; postAuthResponse.paymentLink = paymentLinkResponse.url; postAuthResponse.linkExpiresAt = paymentLinkResponse.expiresAt; + postAuthResponse.expirationDateTime = AdyenPBLHelper.parseDateTime(paymentLinkResponse.expiresAt); + postAuthResponse.paymentLinkId = paymentLinkResponse.id; return new List { postAuthResponse }; } @@ -208,5 +210,11 @@ public with sharing class AdyenPaymentHelper { @InvocableVariable public String linkExpiresAt; + + @InvocableVariable + public Datetime expirationDateTime; + + @InvocableVariable + public String paymentLinkId; } } \ No newline at end of file diff --git a/force-app/main/default/classes/AdyenPaymentHelperTest.cls b/force-app/main/default/classes/AdyenPaymentHelperTest.cls index 01f3fbc..b516892 100644 --- a/force-app/main/default/classes/AdyenPaymentHelperTest.cls +++ b/force-app/main/default/classes/AdyenPaymentHelperTest.cls @@ -88,6 +88,7 @@ private class AdyenPaymentHelperTest { Assert.isTrue(postAuthResponses.size() == 1); Assert.areEqual('https://test.payment.link', postAuthResponses[0].paymentLink); Assert.areEqual('2024-01-01T12:00:00+00:00', postAuthResponses[0].linkExpiresAt); - + Assert.areEqual(AdyenPBLHelper.parseDateTime('2024-01-01T12:00:00+00:00'), postAuthResponses[0].expirationDateTime); + Assert.areEqual('PLE5B4575C5A026A2B2', postAuthResponses[0].paymentLinkId); } } \ No newline at end of file diff --git a/force-app/main/default/classes/AdyenPaymentHelperTest.cls-meta.xml b/force-app/main/default/classes/AdyenPaymentHelperTest.cls-meta.xml index f5e18fd..651b172 100644 --- a/force-app/main/default/classes/AdyenPaymentHelperTest.cls-meta.xml +++ b/force-app/main/default/classes/AdyenPaymentHelperTest.cls-meta.xml @@ -1,5 +1,5 @@ - 60.0 + 61.0 Active diff --git a/force-app/main/default/classes/TestDataFactory.cls b/force-app/main/default/classes/TestDataFactory.cls index aee0845..226828c 100644 --- a/force-app/main/default/classes/TestDataFactory.cls +++ b/force-app/main/default/classes/TestDataFactory.cls @@ -346,7 +346,7 @@ public class TestDataFactory { } private static String pblResponse() { - return '{ "url": "https://test.payment.link", "expiresAt": "2024-01-01T12:00:00+00:00" }'; + return '{ "url": "https://test.payment.link", "expiresAt": "2024-01-01T12:00:00+00:00", "id":"PLE5B4575C5A026A2B2"}'; } public static String mockWebhookRequest(String eventCode, String pspReference, String originalReference, String merchantRef, Boolean success) { From d0a0bf53e45be172ca0a32156abaa0a4d06240ea Mon Sep 17 00:00:00 2001 From: Danilo Cardoso Date: Thu, 24 Oct 2024 15:44:11 +0200 Subject: [PATCH 2/3] feat: Payment Link object plus flow changes --- .../flows/OOBO_Card_and_PBL.flow-meta.xml | 63 ++++++- .../Payment_Link__c.object-meta.xml | 171 ++++++++++++++++++ .../fields/Amount__c.field-meta.xml | 11 ++ .../fields/Expire_Date__c.field-meta.xml | 9 + .../fields/Order_Number__c.field-meta.xml | 12 ++ .../fields/Order_Summary__c.field-meta.xml | 13 ++ .../Payment_Method_Used__c.field-meta.xml | 19 ++ .../fields/Shopper_Email__c.field-meta.xml | 11 ++ .../fields/Status__c.field-meta.xml | 36 ++++ .../fields/URL__c.field-meta.xml | 9 + .../listViews/All.listView-meta.xml | 13 ++ .../default/tabs/Payment_Link__c.tab-meta.xml | 5 + manifest/package.xml | 5 + 13 files changed, 375 insertions(+), 2 deletions(-) create mode 100644 force-app/main/default/objects/Payment_Link__c/Payment_Link__c.object-meta.xml create mode 100644 force-app/main/default/objects/Payment_Link__c/fields/Amount__c.field-meta.xml create mode 100644 force-app/main/default/objects/Payment_Link__c/fields/Expire_Date__c.field-meta.xml create mode 100644 force-app/main/default/objects/Payment_Link__c/fields/Order_Number__c.field-meta.xml create mode 100644 force-app/main/default/objects/Payment_Link__c/fields/Order_Summary__c.field-meta.xml create mode 100644 force-app/main/default/objects/Payment_Link__c/fields/Payment_Method_Used__c.field-meta.xml create mode 100644 force-app/main/default/objects/Payment_Link__c/fields/Shopper_Email__c.field-meta.xml create mode 100644 force-app/main/default/objects/Payment_Link__c/fields/Status__c.field-meta.xml create mode 100644 force-app/main/default/objects/Payment_Link__c/fields/URL__c.field-meta.xml create mode 100644 force-app/main/default/objects/Payment_Link__c/listViews/All.listView-meta.xml create mode 100644 force-app/main/default/tabs/Payment_Link__c.tab-meta.xml diff --git a/force-app/main/default/flows/OOBO_Card_and_PBL.flow-meta.xml b/force-app/main/default/flows/OOBO_Card_and_PBL.flow-meta.xml index 7e5e24e..0e809ba 100644 --- a/force-app/main/default/flows/OOBO_Card_and_PBL.flow-meta.xml +++ b/force-app/main/default/flows/OOBO_Card_and_PBL.flow-meta.xml @@ -693,7 +693,7 @@ - Confirmation_Screen + Save_Payment_Link @@ -1676,6 +1676,65 @@ Product2 + + Save_Payment_Link + + 2426 + 6578 + + Confirmation_Screen + + + Amount__c + + cartSummaryTotals.grandTotalAmount + + + + CurrencyIsoCode + + cartSummaryTotals.currencyIsoCode + + + + Expire_Date__c + + Post_Authorize_Payment.expirationDateTime + + + + Name + + Post_Authorize_Payment.paymentLinkId + + + + Order_Number__c + + orderReferenceNumber + + + + Shopper_Email__c + + paymentSelector.shopperEmail + + + + Status__c + + Active + + + + URL__c + + Post_Authorize_Payment.paymentLink + + + Payment_Link__c + true + Get Account for the record Id passed Get_Account @@ -1982,7 +2041,7 @@ Confirmation_Screen 2426 - 6578 + 6686 false true false diff --git a/force-app/main/default/objects/Payment_Link__c/Payment_Link__c.object-meta.xml b/force-app/main/default/objects/Payment_Link__c/Payment_Link__c.object-meta.xml new file mode 100644 index 0000000..391d32e --- /dev/null +++ b/force-app/main/default/objects/Payment_Link__c/Payment_Link__c.object-meta.xml @@ -0,0 +1,171 @@ + + + + Accept + Default + + + Accept + Large + Default + + + Accept + Small + Default + + + CancelEdit + Default + + + CancelEdit + Large + Default + + + CancelEdit + Small + Default + + + Clone + Default + + + Clone + Large + Default + + + Clone + Small + Default + + + Delete + Default + + + Delete + Large + Default + + + Delete + Small + Default + + + Edit + Default + + + Edit + Large + Default + + + Edit + Small + Default + + + List + Default + + + List + Large + Default + + + List + Small + Default + + + New + Default + + + New + Large + Default + + + New + Small + Default + + + SaveEdit + Default + + + SaveEdit + Large + Default + + + SaveEdit + Small + Default + + + Tab + Default + + + Tab + Large + Default + + + Tab + Small + Default + + + View + Default + + + View + Large + Default + + + View + Small + Default + + false + SYSTEM + Deployed + Custom Object used to store details about the Adyen payment by link solution + true + true + false + true + false + true + true + true + true + Private + + + + false + Text + + Payment Links + + Status__c + Expire_Date__c + URL__c + + ReadWrite + Public + diff --git a/force-app/main/default/objects/Payment_Link__c/fields/Amount__c.field-meta.xml b/force-app/main/default/objects/Payment_Link__c/fields/Amount__c.field-meta.xml new file mode 100644 index 0000000..fc0f2e6 --- /dev/null +++ b/force-app/main/default/objects/Payment_Link__c/fields/Amount__c.field-meta.xml @@ -0,0 +1,11 @@ + + + Amount__c + + 18 + false + 3 + false + false + Currency + diff --git a/force-app/main/default/objects/Payment_Link__c/fields/Expire_Date__c.field-meta.xml b/force-app/main/default/objects/Payment_Link__c/fields/Expire_Date__c.field-meta.xml new file mode 100644 index 0000000..131acba --- /dev/null +++ b/force-app/main/default/objects/Payment_Link__c/fields/Expire_Date__c.field-meta.xml @@ -0,0 +1,9 @@ + + + Expire_Date__c + + false + false + false + DateTime + diff --git a/force-app/main/default/objects/Payment_Link__c/fields/Order_Number__c.field-meta.xml b/force-app/main/default/objects/Payment_Link__c/fields/Order_Number__c.field-meta.xml new file mode 100644 index 0000000..4db93b3 --- /dev/null +++ b/force-app/main/default/objects/Payment_Link__c/fields/Order_Number__c.field-meta.xml @@ -0,0 +1,12 @@ + + + Order_Number__c + false + + 64 + false + false + false + Text + false + diff --git a/force-app/main/default/objects/Payment_Link__c/fields/Order_Summary__c.field-meta.xml b/force-app/main/default/objects/Payment_Link__c/fields/Order_Summary__c.field-meta.xml new file mode 100644 index 0000000..d636b73 --- /dev/null +++ b/force-app/main/default/objects/Payment_Link__c/fields/Order_Summary__c.field-meta.xml @@ -0,0 +1,13 @@ + + + Order_Summary__c + SetNull + + OrderSummary + Payment Links + Payment_Links + false + false + false + Lookup + diff --git a/force-app/main/default/objects/Payment_Link__c/fields/Payment_Method_Used__c.field-meta.xml b/force-app/main/default/objects/Payment_Link__c/fields/Payment_Method_Used__c.field-meta.xml new file mode 100644 index 0000000..d61cd8d --- /dev/null +++ b/force-app/main/default/objects/Payment_Link__c/fields/Payment_Method_Used__c.field-meta.xml @@ -0,0 +1,19 @@ + + + Payment_Method_Used__c + + false + false + false + Picklist + + + false + + visa + false + + + + + diff --git a/force-app/main/default/objects/Payment_Link__c/fields/Shopper_Email__c.field-meta.xml b/force-app/main/default/objects/Payment_Link__c/fields/Shopper_Email__c.field-meta.xml new file mode 100644 index 0000000..5e9ffdb --- /dev/null +++ b/force-app/main/default/objects/Payment_Link__c/fields/Shopper_Email__c.field-meta.xml @@ -0,0 +1,11 @@ + + + Shopper_Email__c + false + + false + false + false + Email + false + diff --git a/force-app/main/default/objects/Payment_Link__c/fields/Status__c.field-meta.xml b/force-app/main/default/objects/Payment_Link__c/fields/Status__c.field-meta.xml new file mode 100644 index 0000000..ad44fc6 --- /dev/null +++ b/force-app/main/default/objects/Payment_Link__c/fields/Status__c.field-meta.xml @@ -0,0 +1,36 @@ + + + Status__c + "Active" + + true + false + false + Picklist + + true + + false + + Active + false + + + + Completed + false + + + + Expired + false + + + + Payment Pending + false + + + + + diff --git a/force-app/main/default/objects/Payment_Link__c/fields/URL__c.field-meta.xml b/force-app/main/default/objects/Payment_Link__c/fields/URL__c.field-meta.xml new file mode 100644 index 0000000..a0d28bd --- /dev/null +++ b/force-app/main/default/objects/Payment_Link__c/fields/URL__c.field-meta.xml @@ -0,0 +1,9 @@ + + + URL__c + + false + false + false + Url + diff --git a/force-app/main/default/objects/Payment_Link__c/listViews/All.listView-meta.xml b/force-app/main/default/objects/Payment_Link__c/listViews/All.listView-meta.xml new file mode 100644 index 0000000..162f036 --- /dev/null +++ b/force-app/main/default/objects/Payment_Link__c/listViews/All.listView-meta.xml @@ -0,0 +1,13 @@ + + + All + NAME + Amount__c + Expire_Date__c + Status__c + Shopper_Email__c + URL__c + CREATED_DATE + Everything + + diff --git a/force-app/main/default/tabs/Payment_Link__c.tab-meta.xml b/force-app/main/default/tabs/Payment_Link__c.tab-meta.xml new file mode 100644 index 0000000..4981c3a --- /dev/null +++ b/force-app/main/default/tabs/Payment_Link__c.tab-meta.xml @@ -0,0 +1,5 @@ + + + true + Custom21: Computer + diff --git a/manifest/package.xml b/manifest/package.xml index de8d987..07981b5 100644 --- a/manifest/package.xml +++ b/manifest/package.xml @@ -33,6 +33,7 @@ AlternativePaymentMethod Payment PaymentAuthorization + Payment_Link__c CustomObject @@ -92,5 +93,9 @@ OOBO_Card_and_PBL Flow + + Payment_Link__c + CustomTab + 61.0 From 30dfe010c681dc1a60b39732ecf8c2d00fe39fe6 Mon Sep 17 00:00:00 2001 From: Danilo Cardoso Date: Thu, 24 Oct 2024 16:04:48 +0200 Subject: [PATCH 3/3] fix: PBLHelperTest class. --- force-app/main/default/classes/AdyenPBLHelperTest.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/main/default/classes/AdyenPBLHelperTest.cls b/force-app/main/default/classes/AdyenPBLHelperTest.cls index cfe29d4..379d1bf 100644 --- a/force-app/main/default/classes/AdyenPBLHelperTest.cls +++ b/force-app/main/default/classes/AdyenPBLHelperTest.cls @@ -96,7 +96,7 @@ private class AdyenPBLHelperTest { Integer days = 5; // When - String expectedDate = Datetime.now().addDays(days).formatGMT('yyyy-MM-dd\'T\'HH:mm:ss'); + String expectedDate = Datetime.now().addDays(days).format('yyyy-MM-dd\'T\'HH:mm:ssXXX'); String expiryDate = AdyenPBLHelper.getLinkExpiryDate(days); // Then