toJson static method
Map<String, dynamic>
toJson({
- required PaymentRequest request,
- required WalletPaymentResult wallet,
- required String walletType,
Builds /sdk/payment payload for wallet flows (Apple Pay / Google Pay).
Implementation
static Map<String, dynamic> toJson({
required PaymentRequest request,
required WalletPaymentResult wallet,
required String walletType,
}) {
if (request.orderDetails.isEmpty) {
throw StateError(
'PaymentRequest.orderDetails must not be empty for wallet payment JSON.',
);
}
final order = request.orderDetails.first;
final conv = order.convenienceFee.trim();
return {
'data': {
'action': request.action,
'class': 'ECOM',
'capture_method': 'MANUAL',
'type': walletType,
'customer_details': {
'm_customer_id': request.customerDetails.mCustomerId,
'name': request.customerDetails.name,
'email': request.customerDetails.email,
'mobile': request.customerDetails.mobile,
'code': request.customerDetails.code,
},
'billing_details': ({
'address_line1': request.billingDetails.addressLine1,
'address_line2': request.billingDetails.addressLine2,
'city': request.billingDetails.city,
'province': request.billingDetails.province,
'country': request.billingDetails.country,
'pin': request.billingDetails.pin,
}),
'order_details': ({
'm_order_id': order.mOrderId,
'amount': order.amount,
'currency': order.currency,
'convenience_fee': conv.isEmpty ? '' : conv,
'description': order.description,
}),
'token': {
'paymentData': wallet.token.toJson(),
'paymentMethod': wallet.paymentMethod.toJson(),
'transactionIdentifier': wallet.transactionIdentifier,
},
if (_shippingDetailsJson(request.shippingDetails).isNotEmpty)
'shipping_details': _shippingDetailsJson(request.shippingDetails),
if (request.urls != null && request.urls!.webhookUrl.trim().isNotEmpty)
'urls': {'webhook_url': request.urls!.webhookUrl.trim()},
'parameters': request.parameters,
'custom_data': request.customData,
},
};
}