Skip to content

Commit

Permalink
Fix Kofi donation payload format (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis authored Dec 26, 2024
1 parent 3256e81 commit aabda16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 41 deletions.
9 changes: 7 additions & 2 deletions service/application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ def get_export_data(token: str):
return person.get_export_data(token=token)

@post('/kofi-donation')
@validate(t.PostKofiData)
def post_kofi_donation(req: t.PostKofiData):
def post_kofi_donation():
try:
data = request.form.get('data')
j = json.loads(data)
req = t.PostKofiData(**j)
except:
return '', 401
return person.post_kofi_donation(req=req)
49 changes: 10 additions & 39 deletions test/functionality1/kofi-donation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,11 @@ set

echo 'Invalid tokens are ignored'

jc POST /kofi-donation -d '{
"verification_token": "invalid-token",
"message_id": "4859ebc6-6721-4e93-9f8e-12dc08d1cda4",
"timestamp": "2024-12-26T10:52:52Z",
"type": "Donation",
"is_public": true,
"from_name": "Jo Example",
"message": "Good luck with the integration!",
"amount": "3.00",
"url": "https://ko-fi.com/Home/CoffeeShop?txid=00000000-1111-2222-3333-444444444444",
"email": "jo.example@example.com",
"currency": "USD",
"is_subscription_payment": false,
"is_first_subscription_payment": false,
"kofi_transaction_id": "00000000-1111-2222-3333-444444444444",
"shop_items": null,
"tier_name": null,
"shipping": null
}'
SESSION_TOKEN="" c \
POST \
/kofi-donation \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode 'data={"verification_token":"invalid-token","message_id":"8d737342-2311-429f-b920-f6e98cde402e","timestamp":"2024-12-26T12:32:57Z","type":"Donation","is_public":true,"from_name":"Jo Example","message":"Good luck with the integration!","amount":"3.00","url":"https://ko-fi.com/Home/CoffeeShop?txid=00000000-1111-2222-3333-444444444444","email":"jo.example@example.com","currency":"USD","is_subscription_payment":false,"is_first_subscription_payment":false,"kofi_transaction_id":"00000000-1111-2222-3333-444444444444","shop_items":null,"tier_name":null,"shipping":null}'

actual=$(q "select estimated_end_date from funding")
expected='2024-09-17 15:02:10.866'
Expand All @@ -56,25 +41,11 @@ echo 'The estimated end date increases when adding 50.0 dollars'

test_token_hash=$(sha512sum <<< "test-token")

jc POST /kofi-donation -d '{
"verification_token": "valid-token",
"message_id": "4859ebc6-6721-4e93-9f8e-12dc08d1cda4",
"timestamp": "2024-12-26T10:52:52Z",
"type": "Donation",
"is_public": true,
"from_name": "Jo Example",
"message": "Good luck with the integration!",
"amount": "50.00",
"url": "https://ko-fi.com/Home/CoffeeShop?txid=00000000-1111-2222-3333-444444444444",
"email": "jo.example@example.com",
"currency": "USD",
"is_subscription_payment": false,
"is_first_subscription_payment": false,
"kofi_transaction_id": "00000000-1111-2222-3333-444444444444",
"shop_items": null,
"tier_name": null,
"shipping": null
}'
SESSION_TOKEN="" c \
POST \
/kofi-donation \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode 'data={"verification_token":"valid-token","message_id":"8d737342-2311-429f-b920-f6e98cde402e","timestamp":"2024-12-26T12:32:57Z","type":"Donation","is_public":true,"from_name":"Jo Example","message":"Good luck with the integration!","amount":"50.00","url":"https://ko-fi.com/Home/CoffeeShop?txid=00000000-1111-2222-3333-444444444444","email":"jo.example@example.com","currency":"USD","is_subscription_payment":false,"is_first_subscription_payment":false,"kofi_transaction_id":"00000000-1111-2222-3333-444444444444","shop_items":null,"tier_name":null,"shipping":null}'

actual=$(q "select estimated_end_date from funding")
expected='2024-10-01 15:02:10.866'
Expand Down

0 comments on commit aabda16

Please sign in to comment.