nicolasgomollon / AppSales-Mobile

AppSales allows iOS and Mac App Store developers to download and analyze their daily and weekly sales reports from iTunes Connect.
39 stars 10 forks source link

Improvements to Payments #26

Closed sirnacnud closed 7 years ago

sirnacnud commented 7 years ago

I have made multiple improvements to the payment data that is stored and displayed.

After this change, all payment data will have to be downloaded again, as we store each individual payment report, rather than summing up the payment reports like in the old method.

nicolasgomollon commented 7 years ago

Great work! Thanks for the help!

A few things I noticed, and fixed in the latest commit after merging your pull request:

sirnacnud commented 7 years ago

Sorry for not covering those cases, I only have a single Vendor ID with my ITC account. Out of curiosity, what kind of payment report is neither paid or expected? All of mine are one or the other.

nicolasgomollon commented 7 years ago

About four years ago, I changed my iTunes Connect details to reflect my company name, rather than my personal name, and as part of that process, a new Vendor ID was created. As a result, I stopped receiving payments under that old Vendor ID, but somehow, a small amount was still associated with it, and it now seems to have gone into limbo, with the Payments Reports showing it as such. Apple still recognizes that I’m owed this $3.25, but it seems to have gotten stuck in that original transition.

You can see the effects of this under reportSummaries, where "isPaymentExpected": false and "paidOrExpectingPaymentDate": "". In particular, the empty paidOrExpectingPaymentDate string was throwing off the code. It’s admittedly an edge case, but it was enough to through the app off.

{
    "data": {
        "vendorName": "Acme Corporation",
        "sapVendorNumber": 12345678,
        "lastSoldUnit": 0,
        "reportDate": "2017-02-01T00:00:00Z",
        "updatedDate": "2017-02-01T00:00:00Z",
        "isPooled": false,
        "reportSummaries": [{
            "status": "PENDING_PAYMENT",
            "returnMessage": null,
            "amount": "3.25",
            "currency": "USD",
            "bankName": "",
            "maskedBankAccount": "",
            "isPaymentExpected": false,
            "paidOrExpectingPaymentDate": "",
            "proceedsByRegion": [{
                "regionCurrency": {
                    "regionCurrencyId": 10004,
                    "regionId": 10004,
                    "regionName": "United Kingdom",
                    "regionNameKey": "ITC.Financial.MZPaymentConsolidation.region.GB",
                    "currencyCode": "GBP"
                },
                "unitsSold": 0,
                "beginBalance": "0.36",
                "earned": "0.00",
                "total": "0.36",
                "taxesAndFees": "0.00",
                "withHoldingTax": "0.00",
                "inputTax": "0.00",
                "adjustmentAmount": "0.00",
                "totalOwed": "0.36",
                "exchangeRate": "",
                "proceeds": "0.45",
                "availableReportTypes": null
            }, {
                "regionCurrency": {
                    "regionCurrencyId": 10000,
                    "regionId": 10000,
                    "regionName": "Americas",
                    "regionNameKey": "ITC.Financial.MZPaymentConsolidation.region.US",
                    "currencyCode": "USD"
                },
                "unitsSold": 0,
                "beginBalance": "2.80",
                "earned": "0.00",
                "total": "2.80",
                "taxesAndFees": "0.00",
                "withHoldingTax": "0.00",
                "inputTax": "0.00",
                "adjustmentAmount": "0.00",
                "totalOwed": "2.80",
                "exchangeRate": "",
                "proceeds": "2.80",
                "availableReportTypes": null
            }]
        }]
    },
    "messages": {
        "warn": null,
        "error": null,
        "info": null
    },
    "statusCode": "SUCCESS"
}
Morpheus2002 commented 7 years ago

All my payments are gone after this update! WTF???

sirnacnud commented 7 years ago

All your payments will need to be redownloaded. Payments are normally downloaded only when there are new reports for the day.

Morpheus2002 commented 7 years ago

I have payments from 2012. Will they redownload too? I doubt that...

sirnacnud commented 7 years ago

If the reports are available in iTunesConnect they should download.

Morpheus2002 commented 7 years ago

That's the point! I doubt my old reports are still available in ITC to download. How can I get them back?

nicolasgomollon commented 7 years ago

@Morpheus2002 Yes, they will all redownload. All of my payments have redownloaded, and they go all the way back to 2010.

nicolasgomollon commented 7 years ago

@Morpheus2002 Additionally, the payments are still saved in the database (they were never actually deleted). You’ll just need to download the AppSales app container using Xcode.

nicolasgomollon commented 7 years ago

@Morpheus2002 Just make sure that you allow the app enough time to download all of them (it may take a few minutes).

Morpheus2002 commented 7 years ago

@nicolasgomollon I got 2 vendor IDs too. Did it work with both of them? Can you tell me where is the counter, so the reports are downloaded once a day? Don't want to wait until tomorrow and need to change this counter, so I can download my reports now.

nicolasgomollon commented 7 years ago

@Morpheus2002 Yes, it works just as before. Payments from both Vendor IDs were downloaded and aggregated for each month.

You can actually go into the “Sales and Trends” section of the app, long press on the latest report on the graph, and then tap “Delete”. You should now be able to tap on the refresh button for the report to redownload, and the payments to download as well.

Morpheus2002 commented 7 years ago

I deleted the last report and tapped on the refresh button. The deleted report was redownloaded, but no payments ... Still got a totally empty payments section.

nicolasgomollon commented 7 years ago

@Morpheus2002 Oh, alright, sorry about that! You can comment out this section from Classes/Report Download/ReportDownloadOperation.m (lines 289-303), and replace it with the following:

{
    [self downloadProgress:0.9f withStatus:NSLocalizedString(@"Loading payments...", nil)];

    LoginManager *loginManager = [[LoginManager alloc] initWithAccount:_account];
    loginManager.shouldDeleteCookies = [[NSUserDefaults standardUserDefaults] boolForKey:kSettingDeleteCookies];
    loginManager.delegate = self;
    [loginManager logIn];
}

NOTE: The curly braces are necessary in order to keep Xcode from complaining about redefining the loginManager variable.

Morpheus2002 commented 7 years ago

@nicolasgomollon it worked!!! Thank you very much!

Morpheus2002 commented 7 years ago

I was able to download only one payment for January. No further payment are downloaded.

sirnacnud commented 7 years ago

I did discover an issue with payment reports and with #28, payment reports will be re-downloaded if they contain no payment summaries. Maybe this fixes your issue?

Morpheus2002 commented 7 years ago

Thanks @sirnacnud! This fixed my issue.