HatangCommerce class

How purchases started from chat cards are handled.

By default "Buy" on a product card writes "I'd like to buy …" in the composer, and a payment card shows a VietQR code and a "Pay now" button that opens the web checkout. That is right for physical goods and real-world services.

App stores forbid external payment for digital goods and features used inside the app: those must be sold through in-app purchase (Apple App Store Review Guideline 3.1.1, Google Play's payments policy). For such apps, handle the purchase yourself and turn external checkout off:

await HatangChat.configure(
  siteId: 'site_…',
  appKey: 'hak_…',
  commerce: HatangCommerce(
    showExternalCheckout: !Platform.isIOS,
    onBuyProduct: (context, product) async {
      // Set per product in the dashboard (App Store / Google Play product ID).
      final storeId = Platform.isIOS ? product.appStoreProductId : product.googlePlayProductId;
      if (storeId == null) return false;          // not an in-app product: default behaviour
      await myIapService.buy(storeId);            // e.g. package:in_app_purchase
      return true;
    },
  ),
);
Annotations

Constructors

HatangCommerce({FutureOr<bool> onBuyProduct(BuildContext context, ProductCardItem product)?, FutureOr<bool> onPay(BuildContext context, PaymentCard payment)?, bool showExternalCheckout = true})
Creates the policy.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
onBuyProduct → FutureOr<bool> Function(BuildContext context, ProductCardItem product)?
"Buy" on a product card. Return true when you handled it (for example with an in-app purchase); false falls back to prefilling the composer.
final
onPay → FutureOr<bool> Function(BuildContext context, PaymentCard payment)?
"Pay now" on a payment card. Return true when you handled it; false falls back to the web checkout, when showExternalCheckout allows it.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
showExternalCheckout → bool
Show the VietQR code and open the web checkout from payment cards. Turn off where the store requires in-app purchase. With it off and no onPay, payment cards show the amount and ask the customer to follow the team's instructions.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

standard → const HatangCommerce
The default: external checkout on, no hooks.