Skip to main content

Create Payment Method

Creates a new payment method.

HTTP Request

POST/api/payment/methods

Authorization

Authorization

  • Required: Yes
  • Permission: Admin or Staff
  • Authentication: Token-based (Authorization: Token <your_api_key>)

Request Body

FieldTypeRequiredDescription
backendStringYesBackend identifier for the payment method (zarinpal, pay-on-delivery)
activeBooleanNoWhether the payment method is active (default: true)
orderIntegerNoOrder of the payment method in the list (default: 0)
nameStringYesName of the payment method
imageIntegerNoID of the payment method's logo image
descriptionStringNoDescription of the payment method
settingsObjectNoAdditional settings for the payment method (merchant_id, api_key, etc.)

Example Requests

1import requests
2
3# Create a new payment method
4response = requests.post('http://www.example.com/api/payment/methods', 
5  json={
6      'backend': 'zarinpal',
7      'active': True,
8      'order': 1,
9      'name': 'Credit Card',
10      'image': 123,
11      'description': 'Pay with your credit card.',
12      'settings': {
13          'merchant_id': 'your_merchant_id',
14          'api_key': 'your_api_key'
15      }
16  },
17  headers={'Authorization': 'Token <your_api_key>'}
18)
19print(response.json())
20
21# Create minimal payment method
22response = requests.post('http://www.example.com/api/payment/methods', 
23  json={
24      'backend': 'pay-on-delivery',
25      'name': 'Cash on Delivery'
26  },
27  headers={'Authorization': 'Token <your_api_key>'}
28)
29print(response.json())

Status Codes

CodeDescription
201Payment method created successfully
400Bad request — invalid input
401Unauthorized — authentication required
403Forbidden — insufficient permissions
500Internal server error

Response Fields

FieldTypeDescription
idIntegerUnique ID of the payment method
backendStringBackend identifier for the payment method
activeBooleanWhether the payment method is active
orderIntegerOrder of the payment method in the list
nameStringName of the payment method
image_dataObjectImage details (read-only)
descriptionStringDescription of the payment method
settingsObjectAdditional settings for the payment method
created_atString (ISO 8601)Timestamp when the payment method was created
updated_atString (ISO 8601)Timestamp when the payment method was last updated

Image Data Structure

FieldTypeDescription
idIntegerUnique ID of the image
typeStringFile type (e.g., image/jpeg)
nameStringOriginal file name
sizeIntegerFile size in bytes
human_readable_sizeStringHuman readable file size (e.g., 2.5 MB)
fStringURL to access the image file
widthIntegerImage width in pixels
heightIntegerImage height in pixels
modeStringColor mode (e.g., RGB, CMYK)

Settings Structure

this response field depends on the payment method backend type and may include fields such as:

FieldTypeDescription
merchant_idStringMerchant ID for payment gateway (e.g., Zarinpal)
api_keyStringAPI key for authenticating requests to the payment gateway