Hej Wszystkim,
Potrzebuję zaimplementować płatność PayU w swojej aplikacji. Na stronce PayU podali przykład jak zrobić nową płatność przy użyciu REST API. Mianowicie metoda post powinna zwrócić adres url który może nas przekierować do strony płatności. Przykład ze strony przy użyciu curl działa świetnie:
curl -X POST https://secure.snd.payu.com/api/v2_1/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer d9a4536e-62ba-4f60-8017-6053211d3f47" \
-d '{
"notifyUrl": "https://your.eshop.com/notify",
"customerIp": "127.0.0.1",
"merchantPosId": "300746",
"description": "RTV market",
"currencyCode": "PLN",
"totalAmount": "21000",
"buyer": {
"email": "john.doe@example.com",
"phone": "654111654",
"firstName": "John",
"lastName": "Doe",
"language": "pl"
},
"products": [
{
"name": "Wireless Mouse for Laptop",
"unitPrice": "15000",
"quantity": "1"
},
{
"name": "HDMI cable",
"unitPrice": "6000",
"quantity": "1"
}
]
}'
Jednak kiedy próbuję zrobić to samo z poziomu Pythona:
import requests
import json
payload = {
"notifyUrl": "https://your.eshop.com/notify",
"customerIp": "127.0.0.1",
"merchantPosId": "300746",
"description": "RTV market",
"currencyCode": "PLN",
"totalAmount": "21000",
"buyer": {
"email": "john.doe@example.com",
"phone": "654111654",
"firstName": "John",
"lastName": "Doe",
"language": "pl"
},
"products": [
{
"name": "Wireless Mouse for Laptop",
"unitPrice": "15000",
"quantity": "1"
},
{
"name": "HDMI cable",
"unitPrice": "6000",
"quantity": "1"
}
]
}
headers = {
'Authorization': 'Bearer d9a4536e-62ba-4f60-8017-6053211d3f47',
'Content-Type': 'application/json',
}
to_json= json.dumps(payload)
resp = requests.post('https://secure.snd.payu.com/api/v2_1/orders', data=to_json, headers=headers)
print(resp.text)
Nie będę wklejał całej odpowiedzi bo jest ogromna, ale zamiast jsona dostaję plik html (?). Co zabawne kiedy robię metodę GET, wszystko jest jak być powinno.
Czy ktoś spotkał się z podobnym problemem?