toTabbyInitJson method

Map<String, dynamic> toTabbyInitJson()

JSON body for PayOrc POST .../sdk/tabby/init ({ "data": { ... } }).

Implementation

Map<String, dynamic> toTabbyInitJson() {
  if (orderDetails.isEmpty) {
    throw StateError(
      'PaymentRequest.orderDetails must not be empty for Tabby init JSON.',
    );
  }
  final order = orderDetails.first;
  final conv = order.convenienceFee.trim();
  return {
    'data': {
      'action': action,
      'class': 'ECOM',
      'capture_method': 'MANUAL',
      'type': 'TABBY',
      'customer_details': {
        'm_customer_id': customerDetails.mCustomerId,
        'name': customerDetails.name,
        'email': customerDetails.email,
        'mobile': customerDetails.mobile,
        'code': customerDetails.code,
      },
      'billing_details': ({
        'address_line1': billingDetails.addressLine1,
        'address_line2': billingDetails.addressLine2,
        'city': billingDetails.city,
        'province': billingDetails.province,
        'country': billingDetails.country,
        'pin': billingDetails.pin,
      }),
      'order_details': ({
        'm_order_id': order.mOrderId,
        'amount': order.amount,
        'currency': order.currency,
        'convenience_fee': conv.isEmpty ? '' : conv,
        'description': order.description,
        if (order.quantity.trim().isNotEmpty) 'quantity': order.quantity,
      }),
      if (_shippingDetailsJson().isNotEmpty)
        'shipping_details': _shippingDetailsJson(),
      if (urls != null && urls!.webhookUrl.trim().isNotEmpty)
        'urls': {'webhook_url': urls!.webhookUrl.trim()},
      'parameters': payOrcNormalizedFiveSlots(parameters),
      'custom_data': payOrcNormalizedFiveSlots(customData),
    },
  };
}