Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist payment link details #64

Merged
merged 4 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions force-app/main/default/classes/AdyenPBLHelper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion force-app/main/default/classes/AdyenPBLHelperTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions force-app/main/default/classes/AdyenPaymentHelper.cls
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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<PBLPostAuthResponse> { postAuthResponse };
}

Expand Down Expand Up @@ -110,5 +112,11 @@ public with sharing class AdyenPaymentHelper {

@InvocableVariable
public String linkExpiresAt;

@InvocableVariable
public Datetime expirationDateTime;

@InvocableVariable
public String paymentLinkId;
}
}
2 changes: 2 additions & 0 deletions force-app/main/default/classes/AdyenPaymentHelperTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,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);
}
}
2 changes: 1 addition & 1 deletion force-app/main/default/classes/TestDataFactory.cls
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,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) {
Expand Down
63 changes: 61 additions & 2 deletions force-app/main/default/flows/OOBO_Card_and_PBL.flow-meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@
</value>
</assignmentItems>
<connector>
<targetReference>Confirmation_Screen</targetReference>
<targetReference>Save_Payment_Link</targetReference>
</connector>
</assignments>
<assignments>
Expand Down Expand Up @@ -1676,6 +1676,65 @@
</inputAssignments>
<object>Product2</object>
</recordCreates>
<recordCreates>
<name>Save_Payment_Link</name>
<label>Save Payment Link</label>
<locationX>2426</locationX>
<locationY>6578</locationY>
<connector>
<targetReference>Confirmation_Screen</targetReference>
</connector>
<inputAssignments>
<field>Amount__c</field>
<value>
<elementReference>cartSummaryTotals.grandTotalAmount</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>CurrencyIsoCode</field>
<value>
<elementReference>cartSummaryTotals.currencyIsoCode</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>Expire_Date__c</field>
<value>
<elementReference>Post_Authorize_Payment.expirationDateTime</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>Name</field>
<value>
<elementReference>Post_Authorize_Payment.paymentLinkId</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>Order_Number__c</field>
<value>
<elementReference>orderReferenceNumber</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>Shopper_Email__c</field>
<value>
<elementReference>paymentSelector.shopperEmail</elementReference>
</value>
</inputAssignments>
<inputAssignments>
<field>Status__c</field>
<value>
<stringValue>Active</stringValue>
</value>
</inputAssignments>
<inputAssignments>
<field>URL__c</field>
<value>
<elementReference>Post_Authorize_Payment.paymentLink</elementReference>
</value>
</inputAssignments>
<object>Payment_Link__c</object>
<storeOutputAutomatically>true</storeOutputAutomatically>
</recordCreates>
<recordLookups>
<description>Get Account for the record Id passed</description>
<name>Get_Account</name>
Expand Down Expand Up @@ -1982,7 +2041,7 @@
<name>Confirmation_Screen</name>
<label>Confirmation Screen</label>
<locationX>2426</locationX>
<locationY>6578</locationY>
<locationY>6686</locationY>
<allowBack>false</allowBack>
<allowFinish>true</allowFinish>
<allowPause>false</allowPause>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<actionOverrides>
<actionName>Accept</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Accept</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Accept</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>CancelEdit</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>CancelEdit</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>CancelEdit</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Clone</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Clone</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Clone</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Delete</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Delete</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Delete</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Edit</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Edit</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Edit</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>List</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>List</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>List</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>New</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>New</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>New</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>SaveEdit</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>SaveEdit</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>SaveEdit</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Tab</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Tab</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>Tab</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>View</actionName>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>View</actionName>
<formFactor>Large</formFactor>
<type>Default</type>
</actionOverrides>
<actionOverrides>
<actionName>View</actionName>
<formFactor>Small</formFactor>
<type>Default</type>
</actionOverrides>
<allowInChatterGroups>false</allowInChatterGroups>
<compactLayoutAssignment>SYSTEM</compactLayoutAssignment>
<deploymentStatus>Deployed</deploymentStatus>
<description>Custom Object used to store details about the Adyen payment by link solution</description>
<enableActivities>true</enableActivities>
<enableBulkApi>true</enableBulkApi>
<enableFeeds>false</enableFeeds>
<enableHistory>true</enableHistory>
<enableLicensing>false</enableLicensing>
<enableReports>true</enableReports>
<enableSearch>true</enableSearch>
<enableSharing>true</enableSharing>
<enableStreamingApi>true</enableStreamingApi>
<externalSharingModel>Private</externalSharingModel>
<label>Payment Link</label>
<nameField>
<label>Payment Link Name</label>
<trackHistory>false</trackHistory>
<type>Text</type>
</nameField>
<pluralLabel>Payment Links</pluralLabel>
<searchLayouts>
<searchResultsAdditionalFields>Status__c</searchResultsAdditionalFields>
<searchResultsAdditionalFields>Expire_Date__c</searchResultsAdditionalFields>
<searchResultsAdditionalFields>URL__c</searchResultsAdditionalFields>
</searchLayouts>
<sharingModel>ReadWrite</sharingModel>
<visibility>Public</visibility>
</CustomObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Amount__c</fullName>
<label>Amount</label>
<precision>18</precision>
<required>false</required>
<scale>3</scale>
<trackHistory>false</trackHistory>
<trackTrending>false</trackTrending>
<type>Currency</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Expire_Date__c</fullName>
<label>Expire Date</label>
<required>false</required>
<trackHistory>false</trackHistory>
<trackTrending>false</trackTrending>
<type>DateTime</type>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Order_Number__c</fullName>
<externalId>false</externalId>
<label>Order Number</label>
<length>64</length>
<required>false</required>
<trackHistory>false</trackHistory>
<trackTrending>false</trackTrending>
<type>Text</type>
<unique>false</unique>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Order_Summary__c</fullName>
<deleteConstraint>SetNull</deleteConstraint>
<label>Order Summary</label>
<referenceTo>OrderSummary</referenceTo>
<relationshipLabel>Payment Links</relationshipLabel>
<relationshipName>Payment_Links</relationshipName>
<required>false</required>
<trackHistory>false</trackHistory>
<trackTrending>false</trackTrending>
<type>Lookup</type>
</CustomField>
Loading