development-integrations

Mastering ESHOPMAN Admin API: Navigating Payment Collections for Advanced Order Workflows

In the dynamic world of headless commerce, ESHOPMAN stands out as a powerful platform, seamlessly integrating with HubSpot to empower merchants with unparalleled control over their storefronts. Built on Node.js/TypeScript, ESHOPMAN leverages robust Admin and Store APIs to facilitate everything from product management to intricate order fulfillment. For developers building sophisticated e-commerce solutions, the Admin API is a critical tool for backend operations, especially when it comes to managing orders and their associated payment collections.

As ESHOPMAN continues to evolve, driven by community insights and the ever-expanding needs of modern commerce, certain areas present unique challenges and opportunities for enhancement. A recent discussion within the ESHOPMAN development community brought to light a crucial aspect of order management: the comprehensive handling of payment collections, particularly when integrating diverse payment methods into HubSpot-managed storefronts.

In-content image: Flowchart illustrating ESHOPMAN Admin API payment collection and detail addition process.
In-content image: Flowchart illustrating ESHOPMAN Admin API payment collection and detail addition process.

The Challenge: Granular Payment Provider Details in Admin API Collections

A key insight from ESHOPMAN developers points to a current limitation within the Admin API when creating payment collections for draft orders or manual order adjustments. Unlike the flexible and comprehensive cart flow offered by the Store API, the Admin API presently lacks direct, built-in support for specifying payment providers and their associated data at the precise moment of payment collection creation.

This means that when developers are working to programmatically create a payment collection and simultaneously attach specific payment details—such as a unique payment provider identifier (e.g., for cash-on-delivery, point-of-sale systems, or manual bank transfers) or provider-specific metadata (like a terminal reference number, an external transaction ID, or specific authorization codes)—the Admin API's initial data structure for collection creation does not inherently accommodate these properties. This can pose a challenge for businesses that rely heavily on custom payment methods or require detailed reconciliation data from the outset of a payment collection.

Technical Deep Dive: Understanding the Type Limitation

From a Node.js/TypeScript development perspective, this limitation manifests as a type mismatch or missing properties within the API's expected payload. The AdminCreatePaymentCollection type, which dictates the structure of data sent to the Admin API for initiating a payment collection, is designed to be lean, primarily focusing on the order_id and the amount of the collection.

Consequently, when developers attempt to include properties like payments[], provider_id, or provider_data directly within the initial creation payload, the TypeScript compiler flags an error. This indicates that these properties are not recognized as valid members of the AdminCreatePaymentCollection type. The provided code snippet illustrates this exact scenario:

await sdk.admin.paymentCollection.create({
  order_id: order.id,
  amount: paymentAmount,
  payments: [
    {
      amount: paymentAmount,
      provider_id: "pp_cash_pos",
      provider_data: {
        cash_paid: paymentAmount,
        // ... other provider-specific data
      }
    }
  ]
});

Attempting to execute this code would result in a TypeScript error similar to: Property 'payments' does not exist on type 'AdminCreatePaymentCollectionPayload'. This highlights that while the intent is to create a collection and immediately link a payment, the API's design separates these actions.

Implications for ESHOPMAN Developers and HubSpot Storefronts

This design choice has several implications for developers building on ESHOPMAN, particularly those managing complex order flows within HubSpot CMS-deployed storefronts:

  • Custom Payment Method Integration: For businesses using unique payment methods (e.g., specific regional bank transfers, custom loyalty points, or in-store payments via a proprietary POS system), the initial creation of a payment collection cannot directly capture the nuances of these methods.
  • Manual Order Processing: When sales teams or customer service agents manually create or adjust orders via the Admin API, they might need to perform additional steps to fully log the payment details, leading to multi-step workflows.
  • Reconciliation Challenges: Without immediate provider data, reconciling payments with external systems or generating detailed financial reports can require more complex post-processing logic to fetch and associate payment details.
  • Developer Experience: It necessitates a two-step (or more) process: first creating the collection, then subsequently adding payment details via a separate API call or custom logic, which can add complexity to development efforts.

Strategies and Best Practices for ESHOPMAN Developers

While the Admin API's initial payment collection creation focuses on core collection data, ESHOPMAN's extensibility and the broader API ecosystem offer robust ways to manage granular payment details:

  1. Separate API Calls: The most straightforward approach is to create the payment collection first using the admin.paymentCollection.create endpoint with the required order_id and amount. Subsequently, use a separate API call (e.g., admin.payment.create, if available, or a custom endpoint) to add the actual payment details, including provider_id and provider_data, linking it to the newly created collection. This ensures data integrity and adherence to the API's design.
  2. Leveraging ESHOPMAN's Extensibility: ESHOPMAN's Node.js/TypeScript foundation allows for custom service layers. Developers can build a wrapper function or a custom service that orchestrates these multiple API calls, abstracting the complexity into a single, cohesive operation from their application's perspective.
  3. Post-Collection Processing and Webhooks: Implement webhooks or event listeners that trigger after a payment collection is created. These listeners can then fetch additional data, interact with external payment gateways, and update the payment collection or associated payment records with provider-specific information. This is particularly useful for asynchronous payment flows.
  4. Utilizing HubSpot for Metadata: For specific use cases, developers might leverage HubSpot's flexible CRM properties to store additional payment-related metadata on the associated order or customer records, which can then be synchronized or referenced by ESHOPMAN.

It's important to remember that the Store API, designed for customer-facing cart and checkout flows, offers a more integrated experience for payment creation, allowing providers and their data to be specified as part of the checkout process. The Admin API, by contrast, is optimized for backend administrative tasks, where payment details might be added or adjusted in a more controlled, multi-step manner.

The ESHOPMAN Vision: Continuous Evolution for Developers

The ESHOPMAN platform is committed to providing a comprehensive and flexible headless commerce experience. Insights like these from the developer community are invaluable, guiding the continuous evolution of the Admin and Store APIs. Addressing such nuances ensures that ESHOPMAN remains at the forefront of empowering merchants and developers to build highly customized, efficient, and scalable e-commerce solutions within the HubSpot ecosystem.

As ESHOPMAN grows, expect ongoing enhancements that streamline complex workflows and provide even greater granularity in managing every aspect of your HubSpot-powered storefront. Developers are encouraged to continue sharing their experiences and use cases, as this collaborative approach is key to shaping the future of headless commerce with ESHOPMAN.

Stay tuned to Move My Store for more updates and expert insights on maximizing your ESHOPMAN implementation!

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools