HomeGuidesAPI Reference
Log In
Guides

Payment

In this guide we'll demonstrate utilizing the Payment APIs for creating orders.

Create Payment Method

In order to create an order using the Create Order API, a payment_method_id representing either your payment method or the end consumer's payment method must be provided.

Here's an example Create Payment Method API request that demonstrates creating a payment method for an example user with the email [email protected] and user ID 7B36A9CF.

curl --request POST \
     --url https://api.mealme.ai/payment/create \
     --header 'Id-Token: <API KEY>' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "payment_method": {
    "card_number": 4242424242424242,
    "expiration_year": 2034,
    "expiration_month": 12,
    "cvc": 123
  },
  "user_email": "[email protected]",
  "user_id": "7B36A9CF"
}
'
{
  "status": "Successfully created payment method",
  "payment_method_id": "pm_1MupdLEFrDExIlIkSl6aeDLg"
}

📘

  • The first successful request for any given user_email will permanently attach the user_id to the user_email. This means that all subsequent requests including the same user_email must also provide the same user_id, else they will fail.
  • A payment_method_id created using your sandbox API key can only be used in Create Order API requests using your sandbox API key. The same applies when using your production API key.
  • When using your sandbox API key, the following requirements must be met:
    • card_number must be 4242424242424242
    • expiration_year and expiration_month must be a valid future date
    • cvc can be any 3-digit number

List Payment Methods

All of a user's payment methods, previously created using the Create Payment Method API, can be retrieved using the List Payment Methods API.

Here's an List Payment Methods API example request that demonstrates retrieving payment methods for the example user we created a payment method for in the Create Payment Method guide.

curl --request GET \
     --url 'https://api.mealme.ai/payment/list?user_id=7B36A9CF&[email protected]' \
     --header 'Id-Token: <API KEY>' \
     --header 'accept: application/json'
{
  "payment_methods": [
    {
      "id": "pm_1MupdLEFrDExIlIkSl6aeDLg",
      "exp_month": 12,
      "exp_year": 2034,
      "last4": "4242",
      "network": "visa"
    }
  ]
}

📘

  • When using your sandbox API key, only payment methods that were created using your sandbox API key will be returned. The same applies when using your production API key.

Delete Payment Method

Here's an Delete Payment Method API example request that demonstrates deleting the payment method that was created for the example user in the Create Payment Method guide.

curl --request POST \
     --url https://api.mealme.ai/payment/delete \
     --header 'Id-Token: <API KEY>' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
  "user_email": "[email protected]",
  "user_id": "7B36A9CF",
  "payment_method_id": "pm_1MupdLEFrDExIlIkSl6aeDLg"
}
'
{
  "status": "Successfully deleted payment method: pm_1MupdLEFrDExIlIkSl6aeDLg"
}

📘

  • When using your sandbox API key, only payment methods that were created using your sandbox API key can be deleted. The same applies when using your production API key.