Skip to content

Commit

Permalink
fix: Adopt ceil method for ios inapp prices
Browse files Browse the repository at this point in the history
  • Loading branch information
jawad-khan committed Aug 4, 2024
1 parent eba5641 commit b1a7f34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions ecommerce/extensions/iap/api/v1/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def test_apply_price_of_inapp_purchase(self, _):
apply_price_of_inapp_purchase(100, '123', headers)

get_call.return_value.status_code = 200
post_call.return_value.status_code = 201
get_call.return_value.json.return_value = {
'data': [
{
Expand All @@ -159,12 +160,11 @@ def test_apply_price_of_inapp_purchase(self, _):
}
]
}
with self.assertRaises(AppStoreRequestException, msg="Couldn't find nearest low price point"):
# Make sure it doesn't select higher price point
apply_price_of_inapp_purchase(80, '123', headers)
with self.assertRaises(AppStoreRequestException, msg="Couldn't find nearest high price point"):
# Make sure it doesn't select lower price point
apply_price_of_inapp_purchase(100, '123', headers)

post_call.return_value.status_code = 201
apply_price_of_inapp_purchase(100, '123', headers)
apply_price_of_inapp_purchase(98, '123', headers)
price_url = 'https://api.appstoreconnect.apple.com/v1/inAppPurchasePriceSchedules'
self.assertEqual(post_call.call_args[0][0], price_url)
self.assertEqual(post_call.call_args[1]['headers'], headers)
Expand Down
15 changes: 8 additions & 7 deletions ecommerce/extensions/iap/api/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,16 @@ def apply_price_of_inapp_purchase(price, in_app_purchase_id, headers):
if response.status_code != 200:
raise AppStoreRequestException("Couldn't fetch price points")

nearest_low_price = nearest_low_price_id = 0
# Apple doesn't allow in app price > 1000
nearest_high_price = nearest_high_price_id = 1001
for price_point in response.json()['data']:
customer_price = float(price_point['attributes']['customerPrice'])
if nearest_low_price < customer_price <= price:
nearest_low_price = customer_price
nearest_low_price_id = price_point['id']
if nearest_high_price > customer_price >= price:
nearest_high_price = customer_price
nearest_high_price_id = price_point['id']

if not nearest_low_price:
raise AppStoreRequestException("Couldn't find nearest low price point")
if nearest_high_price == 1001:
raise AppStoreRequestException("Couldn't find nearest high price point")

url = APP_STORE_BASE_URL + "/v1/inAppPurchasePriceSchedules"
data = {
Expand Down Expand Up @@ -233,7 +234,7 @@ def apply_price_of_inapp_purchase(price, in_app_purchase_id, headers):
"inAppPurchasePricePoint": {
"data": {
"type": "inAppPurchasePricePoints",
"id": nearest_low_price_id
"id": nearest_high_price_id
}
}
},
Expand Down

0 comments on commit b1a7f34

Please sign in to comment.