Unable to receive In-App purchase refund server-to-server notification - ios

I'm trying to implement handling of In-App purchase refund notification (App Store sends responseBody JSON data to server notification url typed by the app developer) in our server backend. But after getting successful refund of In-App purchase, I'm unable to get any notification from the App Store.
Here's the list of things that I did to handle refund notification in our server.
Goto App Store Connect > Type "App Store Notification Url" : "https://ourServerUrl/notifyRefund" (supports TLS 1.2)
Our server accepts 'POST' request and defines #RequestBody parameter as documented in responseBody
Purchase product ('Consumable') from our iOS App (about $0.99) - purchase_date = 2021-03-03
Goto reportaproblem.apple.com and request a refund. -> Next day the refund was processed by App Store and I got $0.99 refunded successfully to my bank account. refund_date = 2021-03-04
After doing above steps I'm still unable to get a notification from App Store.
I read a post about notification delay but I'm not sure if this is because of the delay or my server configuration has a problem.
Apple doc.

Update as of 2021-03-24
In Server <--> App (iOS/Android) communication,
our server's view resolver (ContentNegotiatingViewResolver) determines the default view (TextPlainView, JsonView)
based on the request header (Content-Type, Accept)
Since the apple notification callback response (request to our server)
does not have 'Accept' header, our server sets default view resolver as TextPlainView
following our server configuration in 'servlet-context.xml'
It has caused errors since Apple notification response is in Json format.
After changing our server default view setting as json view
we were able to parse apple notification responseBody.
I hope it helps developers dealing with similar problems.

Related

Flutter in app purchase with backend side calling completePurchase and verifyReceipt

I have a flutter mobile app with a backend. I need to synchronize subscription with backend to share subscription across platforms.
For that I follow this flow :
I create a new account
I initiate new subscription after account has been created
I listen for purchase update and when I receive a purchase details with purchaseDetails.pendingCompletePurchase I send it to backend and use apple verifyReceipt endpoint to check receipt in purchaseDetails.VerificationData.ServerVerificationData
If receipt is valid I save the OriginalTransactionId from purchaseDetails.PurchaseID to database
My question here is:
After it return validation state from server I wonder if I still need to call completePurchase even if I called verifyReceipt endpoint.
I'm not sure to understand what completePurchase really do...
In the end, later I wait for apple server notification to update subscription status

Apple Server to Server notification not receiving from the sandbox for testing subscription renewal

I am trying to update the user's subscription renewal state. I had set up the endpoint in the app information section "URL for App Store Server Notifications" in the app information. But didn't receive any notification. Also, I had tried to set up revenuecat but got no notification. Does anyone know about this issue?

IOS Subscription paid value

I have configured apple Server-to-Server Notifications and it started to send notification to my webhook but the response body doesn't contain any information about paid value nor currency.
I've searched for endpoint to get that info, with no lock
Apple does not include the price in the S2S notification. It is also not present in the receipts validation response (https://developer.apple.com/documentation/appstorereceipts), but the device does have this information ( not sure how they access it), so we get the price info from the device during validation request it sends to our backend.

sending gcm upstream from iOS app when app is not in foreground + gcm API for uploading APNs certificate

I have two questions about APNs push notification using gcm library.
Does gcm or fcm have a public api for uploading APNs certificates? I need to do this automatically instead of manually.
It seems that sending upstream using gcm library in an iOS app, only works when app is in foreground. Is it correct? Is there any workaround to send upstream even when app is not open or is in background? I want to send notification click event using gcm upstream to my server and it is highly preferable to do it instantly.
I am aware that I can save this click event and send it when app become active, but it is possible that user does not open the app for a long time.
1. Does gcm or fcm have a public api for uploading APNs certificates?
There is currently no public API for uploading APNs Certificates. For FCM (and any new projects), it's only done via the Firebase Console. Also, it seems that making use of the APNs Authentication Keys over certificates seem more convenient now (APNs Overview).
2. It seems that sending upstream using gcm library in an iOS app, only works when app is in foreground. Is it correct?
Yes. There has to be a connection for upstream messaging to work.
Is there any workaround to send upstream even when app is not open or is in background?
AFAIK, no. As mentioned in the FCM doc (emphasis mine):
To send messages upstream to the server, an iOS client app composes a message, connects to FCM, and calls sendMessage.
To connect, set the shouldEstablishDirectChannel flag to YES in the AppDelegate. FCM manages the connection, closing it when your app goes into the background and reopening it whenever the app is foregrounded.
...
The FCM client library caches the message on the client app and sends it when the client has an active server connection. On receiving the message, the FCM connection server sends it to the app server.
It mentions that FCM manages the connection, however AFAICT, there is this limitation for iOS devices that limits apps to maintain running services if the app is in background/closed (see this answer). And if a connection can't be established, upstream messaging won't work.
As general practice, data passed through FCM should as much as possible improve the user experience and that no app critical data is passed.
I am aware that I can save this click event and send it when app become active, but it is possible that user does not open the app for a long time.
It's possible. But it's also highly unlikely for a user to not click on a push notification immediately after it displays. In that scenario, the usual action would be for the user to immediately click on the notification while there is still an open connection.

App Deletion - APNS Response to Development Server on Push Notification Failure

I have an iOS app that receives notification from APNS. If my user deletes the app there is no way for the backend to know the app is not installed on a certain device(device token). In this case what error code will be generated when trying to push via APNS, so that i can remove the entry from the database?
There is a Provider (Your backend server) API introduced by Apple in WWDC-2015 & enhanced in 2016 to give more valuable feedback to the server about the push notification. Here is a transcript to that WWDC session.
From the transcript: "If a device token has been removed, you will get an HTTP/2 response with status 410, or "removed."
It will have a time stamp in payload indicating when APNS last learned that the device token has been removed."
APNS Server Response Codes
200 Success
400 Bad request
403 There was an error with the certificate or with the provider
authentication token.
405 The request used a bad :method value. Only POST requests are
supported.
410 The device token is no longer active for the topic.
413 The notification payload was too large.
429 The server received too many requests for the same device token.
500 Internal server error
503 The server is shutting down and unavailable.
Now what I cannot confirm to you is that if iOS removes the device token if app is removed or if notification setting is turned off from App settings without deleting app.
"410 does mean the app was uninstalled. The token will remain active if the user disables notification alerts in the app settings. The device will still receive the notification, even if no alert is shown to the user. The server will not know if the user has turned off notification alerts. Only the app knows this."
Thanks to Marcus Adams for clartfying this doubt.
Here goes the Apple Developer Guide!!!
If required, Here is a Paid SDK that can help you with uninstallation tracking.

Resources