Pay Using Card Information

🚧

Make sure your card method connection is Server to Server.

Using your account Public API Key on the MoneyHashSDK class instance, you can access the functionality of collecting card data and processing payments.

Initialize MoneyHashSDK

Before starting, initialize the MoneyHash SDK with your Public API Key:

final moneyHashSDK = MoneyHashSDK();
moneyHashSDK.setPublicKey("<account_public_api_key>");

Collect Card Data

After setting up the card form as mentioned here, you can collect the card data:

final cardForm = CardFormBuilder().build();
final VaultData? cardData = await cardForm.collect();

You will need to render card form fields to be able to collect customer card information.


Pay

Once you've collected the card data, you can proceed with the payment using the following method:

final IntentDetails? intentDetails = await cardForm.pay(
  "<intent_id>",  // Intent ID
  cardData!,      // Collected card data from cardForm.collect()
  true,           // Optional: Set to `true` to save the card for future use
  {               // Optional: Billing data (Map<String, String>?)
    "address": "123 Main St",
    "city": "New York",
  },
  {               // Optional: Shipping data (Map<String, String>?)
    "address": "456 Elm St",
    "city": "Boston",
  }
);

Refer to the Billing and Shipping Schema if billing and shipping data need to be collected.


📘

Note: saveCard

If you pass true for the saveCard parameter, MoneyHash will tokenize and save the card for future use. This requires the intent to be created with the option "allow_tokenize_card": true for tokenization to work.