2020-04-19 11:13:38 +02:00
|
|
|
from flask import url_for
|
|
|
|
|
|
|
|
from app.extensions import db
|
|
|
|
from app.models import User, ApiKey
|
|
|
|
|
|
|
|
|
|
|
|
def test_apple_process_payment(flask_client):
|
|
|
|
user = User.create(
|
|
|
|
email="a@b.c", password="password", name="Test User", activated=True
|
|
|
|
)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
# create api_key
|
|
|
|
api_key = ApiKey.create(user.id, "for test")
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
receipt_data = """MIIUHgYJKoZIhvcNAQcCoIIUDzCCFAsCAQExCzAJBgUrDgMCGgUAMIIDvwYJKoZIhvcNAQcBoIIDsASCA6wxggOoMAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgEDAgEBBAMMATIwCwIBCwIBAQQDAgEAMAsCAQ8CAQEEAwIBADALAgEQAgEBBAMCAQAwCwIBGQIBAQQDAgEDMAwCAQoCAQEEBBYCNCswDAIBDgIBAQQEAgIAjjANAgENAgEBBAUCAwH8/TANAgETAgEBBAUMAzEuMDAOAgEJAgEBBAYCBFAyNTMwGAIBBAIBAgQQS28CkyUrKkayzHXyZEQ8/zAbAgEAAgEBBBMMEVByb2R1Y3Rpb25TYW5kYm94MBwCAQUCAQEEFCvruJwvAhV9s7ODIiM3KShyPW3kMB4CAQwCAQEEFhYUMjAyMC0wNC0xOFQxNjoyOToyNlowHgIBEgIBAQQWFhQyMDEzLTA4LTAxVDA3OjAwOjAwWjAgAgECAgEBBBgMFmlvLnNpbXBsZWxvZ2luLmlvcy1hcHAwSAIBBwIBAQRAHWlCA6fQTbOn0QFDAOH79MzMxIwODI0g6I8LZ6OyThRArQ6krRg6M8UPQgF4Jq6lIrz0owFG+xn0IV2Rq8ejFzBRAgEGAgEBBEkx7BUjdVQv+PiguvEl7Wd4pd+3QIrNt+oSRwl05KQdBeoBKU78eBFp48fUNkCFA/xaibj0U4EF/iq0Lgx345M2RSNqqWv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Fd/Wpqu6cWNWDS5q3zRinJ6MOL6XnAamFnFbLw/eVovGJfbs+Z3e8bY/6SZasCAwEAAaOBpjCBozAdBgNVHQ4EFgQUiCcXCam2G
|
|
|
|
|
|
|
|
r = flask_client.post(
|
|
|
|
url_for("api.apple_process_payment"),
|
|
|
|
headers={"Authentication": api_key.code},
|
|
|
|
json={"receipt_data": receipt_data},
|
|
|
|
)
|
|
|
|
|
|
|
|
# will fail anyway as there's apple secret is not valid
|
|
|
|
assert r.status_code == 400
|
2020-11-03 16:13:10 +01:00
|
|
|
assert r.json == {"error": "Processing failed"}
|
2020-04-21 09:34:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_apple_update_notification(flask_client):
|
|
|
|
user = User.create(
|
|
|
|
email="a@b.c", password="password", name="Test User", activated=True
|
|
|
|
)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
# create api_key
|
|
|
|
api_key = ApiKey.create(user.id, "for test")
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
payload = {
|
|
|
|
"unified_receipt": {
|
|
|
|
"latest_receipt": "long string",
|
|
|
|
"pending_renewal_info": [
|
|
|
|
{
|
|
|
|
"is_in_billing_retry_period": "0",
|
|
|
|
"auto_renew_status": "0",
|
|
|
|
"original_transaction_id": "1000000654277043",
|
|
|
|
"product_id": "io.simplelogin.ios_app.subscription.premium.yearly",
|
|
|
|
"expiration_intent": "1",
|
|
|
|
"auto_renew_product_id": "io.simplelogin.ios_app.subscription.premium.yearly",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"environment": "Sandbox",
|
|
|
|
"status": 0,
|
|
|
|
"latest_receipt_info": [
|
|
|
|
{
|
|
|
|
"expires_date_pst": "2020-04-20 21:11:57 America/Los_Angeles",
|
|
|
|
"purchase_date": "2020-04-21 03:11:57 Etc/GMT",
|
|
|
|
"purchase_date_ms": "1587438717000",
|
|
|
|
"original_purchase_date_ms": "1587420715000",
|
|
|
|
"transaction_id": "1000000654329911",
|
|
|
|
"original_transaction_id": "1000000654277043",
|
|
|
|
"quantity": "1",
|
|
|
|
"expires_date_ms": "1587442317000",
|
|
|
|
"original_purchase_date_pst": "2020-04-20 15:11:55 America/Los_Angeles",
|
|
|
|
"product_id": "io.simplelogin.ios_app.subscription.premium.yearly",
|
|
|
|
"subscription_group_identifier": "20624274",
|
|
|
|
"web_order_line_item_id": "1000000051891577",
|
|
|
|
"expires_date": "2020-04-21 04:11:57 Etc/GMT",
|
|
|
|
"is_in_intro_offer_period": "false",
|
|
|
|
"original_purchase_date": "2020-04-20 22:11:55 Etc/GMT",
|
|
|
|
"purchase_date_pst": "2020-04-20 20:11:57 America/Los_Angeles",
|
|
|
|
"is_trial_period": "false",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"expires_date_pst": "2020-04-20 20:11:57 America/Los_Angeles",
|
|
|
|
"purchase_date": "2020-04-21 02:11:57 Etc/GMT",
|
|
|
|
"purchase_date_ms": "1587435117000",
|
|
|
|
"original_purchase_date_ms": "1587420715000",
|
|
|
|
"transaction_id": "1000000654313889",
|
|
|
|
"original_transaction_id": "1000000654277043",
|
|
|
|
"quantity": "1",
|
|
|
|
"expires_date_ms": "1587438717000",
|
|
|
|
"original_purchase_date_pst": "2020-04-20 15:11:55 America/Los_Angeles",
|
|
|
|
"product_id": "io.simplelogin.ios_app.subscription.premium.yearly",
|
|
|
|
"subscription_group_identifier": "20624274",
|
|
|
|
"web_order_line_item_id": "1000000051890729",
|
|
|
|
"expires_date": "2020-04-21 03:11:57 Etc/GMT",
|
|
|
|
"is_in_intro_offer_period": "false",
|
|
|
|
"original_purchase_date": "2020-04-20 22:11:55 Etc/GMT",
|
|
|
|
"purchase_date_pst": "2020-04-20 19:11:57 America/Los_Angeles",
|
|
|
|
"is_trial_period": "false",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"expires_date_pst": "2020-04-20 19:11:54 America/Los_Angeles",
|
|
|
|
"purchase_date": "2020-04-21 01:11:54 Etc/GMT",
|
|
|
|
"purchase_date_ms": "1587431514000",
|
|
|
|
"original_purchase_date_ms": "1587420715000",
|
|
|
|
"transaction_id": "1000000654300800",
|
|
|
|
"original_transaction_id": "1000000654277043",
|
|
|
|
"quantity": "1",
|
|
|
|
"expires_date_ms": "1587435114000",
|
|
|
|
"original_purchase_date_pst": "2020-04-20 15:11:55 America/Los_Angeles",
|
|
|
|
"product_id": "io.simplelogin.ios_app.subscription.premium.yearly",
|
|
|
|
"subscription_group_identifier": "20624274",
|
|
|
|
"web_order_line_item_id": "1000000051890161",
|
|
|
|
"expires_date": "2020-04-21 02:11:54 Etc/GMT",
|
|
|
|
"is_in_intro_offer_period": "false",
|
|
|
|
"original_purchase_date": "2020-04-20 22:11:55 Etc/GMT",
|
|
|
|
"purchase_date_pst": "2020-04-20 18:11:54 America/Los_Angeles",
|
|
|
|
"is_trial_period": "false",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"expires_date_pst": "2020-04-20 18:11:54 America/Los_Angeles",
|
|
|
|
"purchase_date": "2020-04-21 00:11:54 Etc/GMT",
|
|
|
|
"purchase_date_ms": "1587427914000",
|
|
|
|
"original_purchase_date_ms": "1587420715000",
|
|
|
|
"transaction_id": "1000000654293615",
|
|
|
|
"original_transaction_id": "1000000654277043",
|
|
|
|
"quantity": "1",
|
|
|
|
"expires_date_ms": "1587431514000",
|
|
|
|
"original_purchase_date_pst": "2020-04-20 15:11:55 America/Los_Angeles",
|
|
|
|
"product_id": "io.simplelogin.ios_app.subscription.premium.yearly",
|
|
|
|
"subscription_group_identifier": "20624274",
|
|
|
|
"web_order_line_item_id": "1000000051889539",
|
|
|
|
"expires_date": "2020-04-21 01:11:54 Etc/GMT",
|
|
|
|
"is_in_intro_offer_period": "false",
|
|
|
|
"original_purchase_date": "2020-04-20 22:11:55 Etc/GMT",
|
|
|
|
"purchase_date_pst": "2020-04-20 17:11:54 America/Los_Angeles",
|
|
|
|
"is_trial_period": "false",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"expires_date_pst": "2020-04-20 17:11:54 America/Los_Angeles",
|
|
|
|
"purchase_date": "2020-04-20 23:11:54 Etc/GMT",
|
|
|
|
"purchase_date_ms": "1587424314000",
|
|
|
|
"original_purchase_date_ms": "1587420715000",
|
|
|
|
"transaction_id": "1000000654285464",
|
|
|
|
"original_transaction_id": "1000000654277043",
|
|
|
|
"quantity": "1",
|
|
|
|
"expires_date_ms": "1587427914000",
|
|
|
|
"original_purchase_date_pst": "2020-04-20 15:11:55 America/Los_Angeles",
|
|
|
|
"product_id": "io.simplelogin.ios_app.subscription.premium.yearly",
|
|
|
|
"subscription_group_identifier": "20624274",
|
|
|
|
"web_order_line_item_id": "1000000051888827",
|
|
|
|
"expires_date": "2020-04-21 00:11:54 Etc/GMT",
|
|
|
|
"is_in_intro_offer_period": "false",
|
|
|
|
"original_purchase_date": "2020-04-20 22:11:55 Etc/GMT",
|
|
|
|
"purchase_date_pst": "2020-04-20 16:11:54 America/Los_Angeles",
|
|
|
|
"is_trial_period": "false",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"expires_date_pst": "2020-04-20 16:11:54 America/Los_Angeles",
|
|
|
|
"purchase_date": "2020-04-20 22:11:54 Etc/GMT",
|
|
|
|
"purchase_date_ms": "1587420714000",
|
|
|
|
"original_purchase_date_ms": "1587420715000",
|
|
|
|
"transaction_id": "1000000654277043",
|
|
|
|
"original_transaction_id": "1000000654277043",
|
|
|
|
"quantity": "1",
|
|
|
|
"expires_date_ms": "1587424314000",
|
|
|
|
"original_purchase_date_pst": "2020-04-20 15:11:55 America/Los_Angeles",
|
|
|
|
"product_id": "io.simplelogin.ios_app.subscription.premium.yearly",
|
|
|
|
"subscription_group_identifier": "20624274",
|
|
|
|
"web_order_line_item_id": "1000000051888825",
|
|
|
|
"expires_date": "2020-04-20 23:11:54 Etc/GMT",
|
|
|
|
"is_in_intro_offer_period": "false",
|
|
|
|
"original_purchase_date": "2020-04-20 22:11:55 Etc/GMT",
|
|
|
|
"purchase_date_pst": "2020-04-20 15:11:54 America/Los_Angeles",
|
|
|
|
"is_trial_period": "false",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"auto_renew_status_change_date": "2020-04-21 04:11:33 Etc/GMT",
|
|
|
|
"environment": "Sandbox",
|
|
|
|
"auto_renew_status": "false",
|
|
|
|
"auto_renew_status_change_date_pst": "2020-04-20 21:11:33 America/Los_Angeles",
|
|
|
|
"latest_expired_receipt": "long string",
|
|
|
|
"latest_expired_receipt_info": {
|
|
|
|
"original_purchase_date_pst": "2020-04-20 15:11:55 America/Los_Angeles",
|
|
|
|
"quantity": "1",
|
|
|
|
"subscription_group_identifier": "20624274",
|
|
|
|
"unique_vendor_identifier": "4C4DF6BA-DE2A-4737-9A68-5992338886DC",
|
|
|
|
"original_purchase_date_ms": "1587420715000",
|
|
|
|
"expires_date_formatted": "2020-04-21 04:11:57 Etc/GMT",
|
|
|
|
"is_in_intro_offer_period": "false",
|
|
|
|
"purchase_date_ms": "1587438717000",
|
|
|
|
"expires_date_formatted_pst": "2020-04-20 21:11:57 America/Los_Angeles",
|
|
|
|
"is_trial_period": "false",
|
|
|
|
"item_id": "1508744966",
|
|
|
|
"unique_identifier": "b55fc3dcc688e979115af0697a0195be78be7cbd",
|
|
|
|
"original_transaction_id": "1000000654277043",
|
|
|
|
"expires_date": "1587442317000",
|
|
|
|
"transaction_id": "1000000654329911",
|
|
|
|
"bvrs": "3",
|
|
|
|
"web_order_line_item_id": "1000000051891577",
|
|
|
|
"version_external_identifier": "834289833",
|
|
|
|
"bid": "io.simplelogin.ios-app",
|
|
|
|
"product_id": "io.simplelogin.ios_app.subscription.premium.yearly",
|
|
|
|
"purchase_date": "2020-04-21 03:11:57 Etc/GMT",
|
|
|
|
"purchase_date_pst": "2020-04-20 20:11:57 America/Los_Angeles",
|
|
|
|
"original_purchase_date": "2020-04-20 22:11:55 Etc/GMT",
|
|
|
|
},
|
|
|
|
"password": "22b9d5a110dd4344a1681631f1f95f55",
|
|
|
|
"auto_renew_status_change_date_ms": "1587442293000",
|
|
|
|
"auto_renew_product_id": "io.simplelogin.ios_app.subscription.premium.yearly",
|
|
|
|
"notification_type": "DID_CHANGE_RENEWAL_STATUS",
|
|
|
|
}
|
|
|
|
|
|
|
|
r = flask_client.post(
|
|
|
|
url_for("api.apple_update_notification"),
|
|
|
|
headers={"Authentication": api_key.code},
|
|
|
|
json=payload,
|
|
|
|
)
|
|
|
|
|
|
|
|
# will fail anyway as there's no such AppleSub in Test DB
|
|
|
|
assert r.status_code == 400
|
2020-11-03 16:13:10 +01:00
|
|
|
assert r.json == {"error": "Processing failed"}
|