renderPaymentMethods method

Future<PaymentMethodWidgetControl> renderPaymentMethods({
  1. required Amount amount,
  2. RenderPaymentMethodsOptions? options,
})

Implementation

Future<PaymentMethodWidgetControl> renderPaymentMethods(
    {required Amount amount, RenderPaymentMethodsOptions? options}) async {
  addJavascriptChannels(_methodWidgetJavascriptChannels);
  this.amount = amount;

  final amountJson = jsonEncode(amount.toJson());
  final optionsJson = jsonEncode(options?.toJson() ?? '');

  String renderScript =
      'const paymentMethodWidget = paymentWidget.renderPaymentMethods(\'#payment-method\', $amountJson, $optionsJson);';
  try {
    await renderWidget(renderScript: renderScript);
    return PaymentMethodWidgetControl._(
      updateAmount: _updateAmount,
      getSelectedPaymentMethod: _getSelectedPaymentMethod,
    );
  } catch (fail) {
    return Future.error(fail);
  }
}