Django полезная нагрузка перед отправкой
Это код для отправки счета через, но я не могу ввести цикл "for loop", чтобы поместить название продукта, цену и количество, так как это сделать, чтобы поместить продукты и другие данные, я пытался добавить цикл for, но он не работает,
###########Send Payment###########
baseURL = "https://apitest.myfatoorah.com"
token = 'rLtt6JWvbUHDDhsZnfpAhpYk4dxYDQkbcPTyGaKp2TYqQgG7FGZ5Th_WD53Oq8Ebz6A53njUoo1w3pjU1D4vs_ZMqFiz_j0urb_BH9Oq9VZoKFoJEDAbRZepGcQanImyYrry7Kt6MnMdgfG5jn4HngWoRdKduNNyP4kzcp3mRv7x00ahkm9LAK7ZRieg7k1PDAnBIOG3EyVSJ5kK4WLMvYr7sCwHbHcu4A5WwelxYK0GMJy37bNAarSJDFQsJ2ZvJjvMDmfWwDVFEVe_5tOomfVNt6bOg9mexbGjMrnHBnKnZR1vQbBtQieDlQepzTZMuQrSuKn-t5XZM7V6fCW7oP-uXGX-sMOajeX65JOf6XVpk29DP6ro8WTAflCDANC193yof8-f5_EYY-3hXhJj7RBXmizDpneEQDSaSz5sFk0sV5qPcARJ9zGG73vuGFyenjPPmtDtXtpx35A-BVcOSBYVIWe9kndG3nclfefjKEuZ3m4jL9Gg1h2JBvmXSMYiZtp9MR5I6pvbvylU_PP5xJFSjVTIz7IQSjcVGO41npnwIxRXNRxFOdIUHn0tjQ-7LwvEcTXyPsHXcMD8WtgBh-wxR8aKX7WPSsT1O8d8reb2aR7K3rkV3K82K_0OgawImEpwSvp9MNKynEAJQS6ZHe_J_l77652xwPNxMRTMASk1ZsJL'
def send_payment():
url = baseURL + "/v2/SendPayment"
payload = "{\"CustomerName\": \"Ahmed\",\"NotificationOption\": \"ALL\",\"MobileCountryCode\": \"+965\"," \
"\"CustomerMobile\": \"12345678\",\"CustomerEmail\": \"xx@yy.com\",\"InvoiceValue\": 100," \
"\"DisplayCurrencyIso\": \"KWD\",\"CallBackUrl\": \"https://google.com\",\"ErrorUrl\": " \
"\"https://google.com\",\"Language\": \"en\",\"CustomerReference\": \"ref 1\",\"CustomerCivilId\": " \
"12345678,\"UserDefinedField\": \"Custom field\",\"ExpireDate\": \"\",\"CustomerAddress\": {\"Block\": " \
"\"\",\"Street\": \"\",\"HouseBuildingNo\": \"\",\"Address\": \"\",\"AddressInstructions\": \"\"}," \
"\"InvoiceItems\": [{\"ItemName\": \"Product 01\",\"Quantity\": 1,\"UnitPrice\": 100}]} "
headers = {'Content-Type': "application/json", 'Authorization': "Bearer " + token}
response = requests.request("POST", url, data=payload, headers=headers)
print("Send Payment Response:\n" + response.text)
Я пробовал это и сделал цикл for, но это не сработало
url = baseURL + "/v2/SendPayment"
sss={'ItemName': 'product 01',
'Quantity': 30,
'UnitPrice': 10,},
payload={
"CustomerName": "name", # Mandatory Field ("string")
"NotificationOption": "SMS", # Mandatory Field ("LNK", "SMS", "EML", or "ALL")
"InvoiceValue": 300, # Mandatory Field (Number)
# Optional Fields
"MobileCountryCode": "+966",
"CustomerMobile": "12345678", #Mandatory if the NotificationOption = SMS or ALL
# "CustomerEmail": "mail@company.com", #Mandatory if the NotificationOption = EML or ALL
"DisplayCurrencyIso": "kwd",
"CallBackUrl": "https://yoursite.com/success",
"ErrorUrl": "https://yoursite.com/error",
"Language": "ar",
# "CustomerReference": "noshipping-nosupplier",
# "CustomerAddress": {
# "Block": "string",
# "Street": "string",
# "HouseBuildingNo": "string",
# "Address": "address",
# "AddressInstructions": "string"
# },
"InvoiceItems": [
sss
]
}
payload=str(payload)
print(f"this is pyload: {payload}")
print(f"this is sss: {sss}")
headers = {'Content-Type': "application/json", 'Authorization': "Bearer " + token}
response = requests.request("POST", url, data=payload2, headers=headers)
print("Send Payment Response:\n" + response.text)
Параметр data
в requests.request должен быть dict
, другими словами, не преобразуйте payload
в строку, пусть это будет dict
.