Skip to main content

Magento Order Header To iPaaS

Synchronize Magento order headers to iPaaS

Updated over 2 weeks ago

Overview

This document outlines the configuration for automatically synchronizing Order Header records from the Magento Order Header entity to the iPaaS Transaction entity. The integration uses an API-based sync that triggers whenever an Order Header record is created in Magento.

Mapping Collection Status

  • Mapping Status: Enabled.

  • Trigger Events: The sync is triggered by the creation of Order Headers in Magento.

  • ID Format: When manually syncing, the Order Header ID from iPaaS is used. This can be resolved via an external ID.

  • Conflicting Mappings: This mapping applies only to Order Headers. Ensure no other mappings target the same Magento entity to prevent data from being overwritten.

Supported Child Collections

The integration supports the synchronization of the parent Order Header and its related child collections:

System Caveats

Magento Caveats

  • Processes only non-deposit transactions (i.e., transactions not ending with “-D”).

  • Excludes gift card transactions (ending with “-GC”) and fraudulent orders (with status “suspected_fraud” or “fraud”).

  • Provides all necessary totals and order details for deposit synchronization.

iPaaS Caveats

  • Receives order records with all associated child records (Lines, Payments, Taxes).

  • Sets the deposit record status to Pending by default.

  • Links Order Headers to their parent transactions via the ParentId field.

Setup Requirements

Magento Configuration

  • IncrementId: Must not end with “-D” or “-GC”.

  • Status: Orders marked as “suspected_fraud” or “fraud” are excluded.

  • Subtotal, TaxAmount, ShippingAmount, DiscountAmount: Required for total calculation.

iPaaS Configuration

  • SystemId: Derived using SpaceportSystemId.

  • ParentId: Retrieved dynamically through lookup for transaction association.

  • Transaction Type: Always set as “Order”.

Authentication & Security

  • Magento2 API UserName: Used to access iPaaS API for fetching Company and related data.

  • Magento2 API Key: Used to access iPaaS API for fetching Company and related data.

Integration Flow

  1. Retrieve Data: Fetch orders from Magento matching the filter conditions.

  2. Apply Filter: Only transactions (!IncrementId.EndsWith("-D") && !IncrementId.EndsWith("-GC") && !(Status == "suspected_fraud") && !(Status == "fraud")) are processed.

  3. Map Fields: Populate fields such as TransactionNumber, Subtotal, Total, and Tax.

  4. Resolve Parent Reference: Fetch related parent transaction via GetSpaceportParentTransactionIdAsync.

  5. Send to iPaaS: Create Order Header record with child records (Lines, Payments, and Taxes).

Mappings

Order Header (Parent)

Filter

!IncrementId.EndsWith("-D") && !IncrementId.EndsWith("-GC") && !(Status == "suspected_fraud") && !(Status == "fraud")

Mapping Type

Source Field (Magento)

Destination Field (iPaaS)

Dynamic Formula

SpaceportSystemId

SystemId

Field

IncrementId

TransactionNumber

Static

Order

Type

Lookup Translation

Status

Field

CustomerEmail

EmailAddress

Field

DiscountAmount

DiscountAmount

Field

TaxAmount

TaxAmount

Field

ShippingAmount

ShippingAmount

Field

Subtotal

Subtotal

Field

GrandTotal

Total

Field

TotalQtyOrdered

TotalQty

Dynamic Formula

CurrentDateTimeOffset()

TransactionCreatedDateTime

Order Bill Address To iPaaS (Child Collection)

Filter

AddressType == "billing"

Mapping Type

Source Field (Magento)

Destination Field (iPaaS)

Static

true

IsPrimaryBilling

Dynamic Formula

(Street.Count > 0 ? Street[0] : Coalesce(Street, ""))

Address1

Dynamic Formula

(Street.Count > 1 ? Street[1] : "")

Address2

Dynamic Formula

(Street.Count > 2 ? Street[2] : "")

Address3

Field

City

City

Field

RegionCode

Region

Field

CountryId

Country

Field

PostCode

PostCode

Field

FirstName

FirstName

Field

LastName

LastName

Field

Company

Company

Order Header Line To iPaaS (Child Collection)

Filter

IsEmpty(ParentItemId) && ProductType != "giftvoucher"

Mapping Type

Source Field (Magento)

Destination Field (iPaaS)

Field

SellUnit

SellingUnit (custom field)

Dynamic Formula

(ProductType == "giftvoucher" ? "Gift Card" : "Product")

Type

Static

Pending

Status

Dynamic Formula

SkuFromOrderLine(Sku.Replace("/", "-"))

Sku

Field

Description

Description

Field

QtyOrdered

Qty

Dynamic Formula

Price - (DiscountAmount / QtyOrdered.Value)

UnitPrice

Field

RowTotal

ExtendedPrice

Field

OriginalPrice

OriginalUnitPrice

Field

DiscountAmount

DiscountAmount

Field

DiscountPercent

DiscountPercent

Field

TaxPercent

TaxPercent

Field

TaxAmount

EstimatedTaxAmount

Field

Weight

Weight

Order Line To iPaaS - Gift Card (Child Collection)

Filter

ProductType == "giftvoucher"

Mapping Type

Source Field (Magento)

Destination Field (iPaaS)

Field

giftcardshippedtorecipient (custom field)

Giftcard Shippedto Recipient(custom field)

Field

giftcardnumber(custom field)

Giftcard Number(custom field)

Field

giftcardcustommessage(custom field)

Giftcard Message(custom field)

Dynamic Formula

var gcNumber = await GetSpaceportIdAsync(giftcardnumber, "Gift Card", SpaceportSystemId); (ProductType =="giftvoucher" ? return JSONToDictionary("{\"GiftCardId\":\"" + gcNumber + "\"}"); : return null;)

LineInfo

Dynamic Formula

(ProductType == "giftvoucher" ? "Gift Card" : "Product")

Type

Static

Pending

Status

Dynamic Formula

Sku.Replace("/", "-")

Sku

Field

Description

Description

Field

QtyOrdered

Qty

Dynamic Formula

Price - DiscountAmount

UnitPrice

Field

RowTotal

ExtendedPrice

Field

OriginalPrice

OriginalUnitPrice

Field

DiscountAmount

DiscountAmount

Field

DiscountPercent

DiscountPercent

Field

TaxPercent

TaxPercent

Field

Weight

Weight

Order Payment To iPaaS (Child Collection)

Filter

Method != "giftcard"

Mapping Type

Source Field (Magento)

Destination Field (iPaaS)

Lookup Translation

Method

Field

Method

Description

Dynamic Formula

(Parent.Status == "pending" ? (ConvertToDecimal(AmountOrdered)-GiftCardSoldTotal(Parent.Items)) : (ConvertToDecimal(AmountPaid)-GiftCardSoldTotal(Parent.Items)))

Amount

Dynamic Formula

(CoalesceToDecimal(BaseAmountPaid,0) > 0 ? "Complete" : "Authorized")

Status

Order Payment To iPaaS -Gift Card (Child Collection)

Filter

Method=="giftcard"

Mapping Type

Source Field (Magento)

Destination Field (iPaaS)

Field

authcode (custom field)

AuthCode (custom field)

Field

giftcardnumber (custom field)

Giftcard Number (custom field)

Dynamic Formula

var gcNumber = await iPaaSGiftCardIdAsync(giftcardnumber); return JSONToDictionary("{\"GiftCardId\":\"" + gcNumber + "\"}");

MethodInfo

Lookup Translation

Method

Field

Method

Description

Dynamic Formula

(Parent.Status == "pending" ? (ConvertToDecimal(AmountOrdered)-GiftCardSoldTotal(Parent.Items)) : (ConvertToDecimal(AmountPaid)-GiftCardSoldTotal(Parent.Items)))

Amount

Static

Complete

Status

Order Ship Address To iPaaS - Flat Rate - Fixed (Child Collection)

Filter

AddressType == "shipping" && Parent.ShippingDescription=="Flat Rate - Fixed"

Mapping Type

Source Field (Magento)

Destination Field (iPaaS)

Static

true

IsPrimaryShipping

Dynamic Formula

(Street.Count > 0 ? Street[0] : Coalesce(Street, ""))

Address1

Dynamic Formula

(Street.Count > 1 ? Street[1] : "")

Address2

Dynamic Formula

(Street.Count > 2 ? Street[2] : "")

Address3

Field

City

City

Field

RegionCode

Region

Field

CountryId

Country

Field

PostCode

PostCode

Static

UPS GROUND

ShippingMethod

Field

FirstName

FirstName

Field

LastName

LastName

Field

Company

Company

Order Ship Address To iPaaS - Unmapped (Child Collection)

Filter

AddressType == "shipping" && !(Parent.ShippingDescription == "Flat Rate - Fixed") && !(Parent.ShippingDescription == "Free Shipping - Free")

Mapping Type

Source Field (Magento)

Destination Field (iPaaS)

Static

true

IsPrimaryShipping

Dynamic Formula

(Street.Count > 0 ? Street[0] : Coalesce(Street, ""))

Address1

Dynamic Formula

(Street.Count > 1 ? Street[1] : "")

Address2

Dynamic Formula

(Street.Count > 2 ? Street[2] : "")

Address3

Field

City

City

Field

RegionCode

Region

Field

CountryId

Country

Field

PostCode

PostCode

Static

UPS GROUND

ShippingMethod

Field

FirstName

FirstName

Field

LastName

LastName

Field

Company

Company

Order Ship Address To iPaaS - Free Shipping (Child Collection)

Filter

AddressType == "shipping" && Parent.ShippingDescription=="Free Shipping - Free"

Mapping Type

Source Field (Magento)

Destination Field (iPaaS)

Static

true

IsPrimaryShipping

Dynamic Formula

(Street.Count > 0 ? Street[0] : Coalesce(Street, ""))

Address1

Dynamic Formula

(Street.Count > 1 ? Street[1] : "")

Address2

Dynamic Formula

(Street.Count > 2 ? Street[2] : "")

Address3

Field

City

City

Field

RegionCode

Region

Field

CountryId

Country

Field

PostCode

PostCode

Static

UPS GROUND

ShippingMethod

Field

FirstName

FirstName

Field

LastName

LastName

Field

Company

Company

Order Header Tax To iPaaS (Child Collection)

Mapping Type

Source Field (Magento)

Destination Field (iPaaS)

Dynamic Formula

(Parent.ExtensionAttributes != null && Parent.ExtensionAttributes.AppliedTaxes != null && Parent.ExtensionAttributes.AppliedTaxes.Count > 0 ? Parent.ExtensionAttributes.AppliedTaxes[0].Title : "Avalara")

Authority

Dynamic Formula

Parent.TaxAmount

Amount

Lookup Translations

M2 Transaction Payment Method To iPaaS

Source Field (Magento)

Destination Field (iPaaS)

authnetcim

CASH

authorizenet

CASH

braintree

CASH

checkmo

CASH

paypal_express

CASH

purchaseorder

CASH

giftcard

GC

M2 Transaction Status Method To iPaaS

Source Field (Magento)

Destination Field (iPaaS)

pending

Pending

processing

Pending

complete

Complete

canceled

Cancelled

completing

Complete

ready_for_completion

Pending

Error Handling

Collection: Order Header Line (Child)

Error: Missing SKU or Product Type

  • Resolution: Ensure all line items contain valid SKU and product type fields.

Collection: Payment (Child)

Error: Payment Method Lookup Failure

  • Resolution: Verify the payment method exists in the M2 Transaction Payment Method Lookup mapping.

Validation Rules & Testing

Validation Rules

  • The transaction number must not end with “-D” or “-GC”

  • Fraudulent and gift card orders excluded.

  • All totals (Subtotal, Tax, Shipping, Discount) correctly computed.

  • Payment and line details correctly linked to parent ticket.

Test Scenarios

  1. Create a valid order: Order record should appear in iPaaS.

  2. Send order with “-GC”: Skipped by filter.

  3. Include invalid totals: Mapping should throw validation error.

  4. Send payment with gift card: Routed to Gift Card Payment child mapping

Additional Notes

  • All child records (Line, Payment, Tax) must reference a valid parent via ParentId.

Did this answer your question?