Skip to content

Conversation

@onbuyuka
Copy link
Contributor

@onbuyuka onbuyuka commented Jan 8, 2026

Summary

This PR improves the Shopify Payments synchronization logic by implementing targeted GraphQL queries to update payment transaction payout IDs and payout statuses in batches, rather than relying on the previous approach that coupled transaction imports with payout imports.

Changes

New GraphQL Codeunits

  • ShpfyGQLPaymTransByIds (ID 30421): New GraphQL query to retrieve payment transactions by ID filter, returning transaction IDs with their associated payout IDs
  • ShpfyGQLPayoutsByIds (ID 30420): New GraphQL query to retrieve payouts by ID filter, returning payout IDs with their statuses

GraphQL Type Enum Extension

  • Added new enum values GetPaymTransByIds (145) and GetPayoutsByIds (146) to ShpfyGraphQLType.Enum.al with implementations pointing to the new codeunits

Payments Codeunit Refactoring

  • ShpfyPayments.Codeunit.al:
    • Renamed SyncPaymentTransactions to SyncPayouts for clarity
    • Added new procedures: UpdatePaymentTransactionPayoutIds and UpdatePendingPayouts
    • Implemented batch processing (up to 200 at a time) for updating transactions without payout IDs and payouts with pending statuses
    • Organized code into #region Payouts and #region Disputes sections

Payments API Enhancements

  • ShpfyPaymentsAPI.Codeunit.al:
    • Added UpdatePaymentTransactionPayoutIds(IdFilter: Text) - queries Shopify for transactions by ID and updates their payout IDs
    • Added UpdatePayouts(IdFilter: Text) - queries Shopify for payouts by ID and updates their statuses
    • Simplified ImportPaymentTransactions signature (removed var parameter)
    • Simplified ImportPaymentTransaction to handle both new record creation and existing record updates
    • Added region organization for better code structure

Report Update

  • ShpfySyncPayments.Report.al: Updated to call the renamed SyncPayouts procedure

Permission Set Update

  • ShpfyObjects.PermissionSet.al: Added execute permissions for the two new GraphQL codeunits

Test Updates

  • ShpfyPaymentsTest.Codeunit.al: Updated test to use the simplified ImportPaymentTransaction signature

Benefits

  1. Targeted Updates: Payment transactions without payout IDs and pending payouts are now updated independently using efficient batch queries
  2. Better Performance: Batch processing with first: 200 reduces API calls when updating multiple records
  3. Cleaner Code: Reorganized with regions and simplified method signatures
  4. Maintainability: Separated concerns between importing new data and updating existing records

Work Item(s)

Fixes #

@github-actions github-actions bot added the AL: Apps (W1) Add-on apps for W1 label Jan 8, 2026
@github-actions
Copy link

github-actions bot commented Jan 8, 2026

Could not find a linked ADO work item. Please link one by using the pattern 'AB#' followed by the relevant work item number. You may use the 'Fixes' keyword to automatically resolve the work item when the pull request is merged. E.g. 'Fixes AB#1234'

if PaymentTransaction.Get(Id) then begin
PaymentTransaction."Payout Id" := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JTransaction, 'associatedPayout.id'));
PaymentTransaction.Modify();
// TODONAT: Anything else to update?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are importing new transactions, so I don't expect Get(id) to return anything ever. Ok to keep modification of Payout Id.

if JsonHelper.GetJsonArray(JResponse, JTransactions, 'data.shopifyPaymentsAccount.balanceTransactions.nodes') then
foreach JNode in JTransactions do begin
Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JNode.AsObject(), 'id'));
PayoutId := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JNode.AsObject(), 'associatedPayout.id'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to parse json before get transaction? Maybe move it inside If-Then below.
though we expect both will be executed.

On the other hand. Do we always want to update Payout Id? shall we check that old value is 0 and new value is not 0?
Will server skip modify if Rec.Payout Id = xRec.Payout Id?

if PaymentTransaction.Get(Id) then begin
PaymentTransaction."Payout Id" := PayoutId;
PaymentTransaction.Modify();
end;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we need:
DataCapture.Add(Database::"Shpfy Payment Transaction", PaymentTransaction.SystemId, JNode);

if JsonHelper.GetJsonObject(JResponse, JPaymentsAccount, 'data.shopifyPaymentsAccount') then
if JsonHelper.GetJsonArray(JResponse, JPayouts, 'data.shopifyPaymentsAccount.payouts.nodes') then
foreach JNode in JPayouts do begin
Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JNode.AsObject(), 'id'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need
DataCapture.Add(Database::"Shpfy Payout", Payout.SystemId, JNode);

end;
end;

internal procedure UpdatePayouts(IdFilter: Text)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be more specific "UpdatePayoutStatus("?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants