What if android crash before saving the purchaseToken? - java

I'm doing my first project using in-app billing on Android but there one thing I don't get:
We need to keep the purchaseToken whenever the purchase was succesfull in order to consume it later on. But there is no way to recover it if we don't save it on the first time we receive it. So if for instance Android crashed or something happens before we have time to consume/to save this token, how should we do then ? We won't ever be able to consume the purchase anymore without this token (which would be terribly anoying)...
To recall, the purchase data is stored in a String in JSON format :
'{
"orderId":"GPA.1234-5678-9012-34567",
"packageName":"com.example.app",
"productId":"exampleSku",
"purchaseTime":1345678900000,
"purchaseState":0,
"developerPayload":"bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ",
"purchaseToken":"opaque-token-up-to-1000-characters"
}'
Do you have any solution or explanation about something I would have misunderstood in the process?

Please refer to getPurchases() api in the following link:
https://developer.android.com/google/play/billing/billing_reference.html#getPurchases
As long as you have yet to consume a purchase, you can get the unconsume purchase from getPurchases() api call. Just call getToken() to retrieve purchaseToken.

Related

Send data to another server when it's updated

I am writing a service which would store picture associated with registered email. So, other domains would have a possibility to get image of the user by email. The main goal is not to upload it each time as nowadays we have to register almost everywhere and that process is quite annoying.
My application is written on Java and I am using REST API.
For example, user's account information is available by login:
#RequestMapping(value = "/get/{login}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
#ResponseBody
public ResponseEntity<User> getByEmail(#PathVariable String login) {
User user = userDao.getUserByLogin(login);
return Optional.ofNullable(user)
.map(result -> new ResponseEntity<>(
result, HttpStatus.OK))
.orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
And now, what i want is to send just updated data to the domains which gonna use my service. How could I figure that out? I think I could ask "domain" to provide some information in order to use my service (some king of registration), but what exactly should I ask for to be able to send data udpdates?
In my thoughts they should also provide some REST path where I could send some kind of request that something has changed.
Any help would be appreciated a lot, thanks.
This is essentially a pub-sub model . You publish some information , on various defined events , to whoever has subscribed to it . Look at this as a subset of state syncronisation of the user information across various endpoints.
In your case , the 'domains' you are referring to would be subscribers of your service and the events could be 'itemAdded' , 'itemAdded' etc. You would want to 'push' out the updates ( or whole info) to the subscribers when the event they have subscribed for occurs , instead of them trying to pull this at some frequency ( that would be a lot of waste calls to your server - you dont want that ! )
There are various solutions available that could achieve this . The one I am going to point you to is called Twilio Sync . This would obviously mean that the 'domains' would have to do some changes at their end to subscribe and consume the updates , but I dont see how else could they be regularly updated if they want information pushed.
Send last update date to the endpoint from the domain which
use it. Then check which data was updated after that date and return
appropriate response.
Talking about image, you can always return URL for download but add last update field. The service which use REST service will determine to download it or not.
Also you may need event driven messaging, publish–subscribe pattern (https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern). Related threads:
How would I create an asynchronous notification system using RESTful web services?
Event Based interaction style in REST
Firebase for mobile apps: https://firebase.google.com/docs/notifications/

How to get the recipient ID on Facebook API v2.4 and newer (RestFB/Facebook4J)

I'm trying to send messages to customers who want to know the current state of their order. Now I know that you can only send messages to someone who sent you a message because you need to have the specific recipient ID. The problem with this is that if I want to get the recipient ID I need to read my mailbox and therefore need the permission: read_mailbox. But read_mailbox is deprecated as of Facebook API v2.4 and newer. I don't think that it is impossible to do it though. Question beeing, how to do it with v2.4 or newer?
Edit: Thanks CBroe for the answer
Last problem now is that when I get a specific message it only gives me the created_time and the id back. Same thing when I try it with the GraphAPI Explorer
This:
JsonObject message = getFacebookClient().fetchObject("m_mid.1467893842385:ae7475981839704062", JsonObject.class);
Gives this:
{
"created_time": "2016-07-07T12:17:22+0000",
"id": "m_mid.1467893842385:ae7475981839704062"
}
What am I doing wrong? Am I missing a parameter or a permission?
No, this doesn’t need read_mailbox permission.
https://developers.facebook.com/docs/graph-api/reference/page/conversations#read:
A page access token with read_page_mailboxes permission is required.
So you have to ask for that permission, plus manage_pages of course (because you need the latter to get a page access token.)

Check the status of In-App Subscription in Android

I have created an application in which there is in-app purchases which has monthly auto renewal.. on first time successful payment i have called a web-service in which i have made the user to premium class.
Now if the user has cancelled the payment manually from the google server, how could i know that user has cancelled his/her subscription.
Is there is some PHP code query or from android i have to called something in background to check the status??
Thank you in advace
I haven't tested this, but could you use the autoRenewing field in INAPP_PURCHASE_DATA?
If true, the subscription is active, and will automatically renew on the next billing date. If false, indicates that the user has canceled the subscription.
http://developer.android.com/google/play/billing/billing_reference.html#getBuyIntent
Apparently, the autoRenewing field was added or at least documented in the beginning of 2015.
You can check the purchased subscriptions inside the app via
Edit: For subscriptions use "subs", for inapp-purchases use "inapp" e.g.:
Inapp-Purchases: mService.getPurchases(3, getPackageName(), "inapp", null);
Subscriptions: mService.getPurchases(3, getPackageName(), "subs", null);
See also Querying for Purchased Items at http://developer.android.com/google/play/billing/billing_integrate.html
So you can implement a task in your app where you check if the user still has a subscription. If not, you can remove the premium status. Moreover this information could be useful for you:
When the user cancels a subscription, Google Play does not offer a refund for the current billing cycle. Instead, it allows the user to have access to the canceled subscription until the end of the current billing cycle, at which time it terminates the subscription. For example, if a user purchases a monthly subscription and cancels it on the 15th day of the cycle, Google Play will consider the subscription valid until the end of the 30th day (or other day, depending on the month).
source: http://developer.android.com/google/play/billing/billing_subscriptions.html under subscription cancelled
Hope this could help you
Edit2: Because the AIDL library which is mentioned in my answer is deprecated and deactivated in the future, it is recommended to switch to the new Google Play Billing Library.
Check the getPurchases() method here. Or if you use Android Studio and have the source code downloaded just press Ctrl + Q on IInAppBillingService.getPurchases method

Paypal express checkout java

I'm integrating paypal express checkout on one website and I'm using PaypalFunctions.java that I've download in the customized example.
I've successfull called, in development environment, the ppf.callMarkExpressCheckout
and after login on Paypal page I've correctly reached my confirmation page where i catch the payerId from the request.
I can't understand if the process is complete or I need to make a further step to get money and end the process.
I have this doubt because the process and the methods name is quite different than the one described in https://developer.paypal.com/docs/classic/express-checkout/gs_expresscheckout/ and I don't receive any mail from paypal dev environment
Kind regards
In express checkout , once the buyer comes to your return url after confirming the Payments from their account you need to call the "DoExpressCheckout" API using the token and the payer id you received on your return url . Until this step completes , No payment will be recorded and hence no emails will be sent out . You can check the documentation for "DoExpressCheckout " API here :
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/DoExpressCheckoutPayment_API_Operation_NVP/
https://developer.paypal.com/webapps/developer/docs/classic/express-checkout/ht_ec-singleItemPayment-curl-etc/
If I got you right, you don't know how pay pal gets back to you. Look for 'returnUrl' (and 'cancelUrl') in https://developer.paypal.com/docs/classic/express-checkout/gs_expresscheckout/ . That's URL pay pal calls on your application once the user authorized the payment on the pay pal site.

Facebook realtime api for feed

I have set up realtime feed update for user. So whenever a user comments or likes something, I get a update request from facebook.
{
object='user',
entry=[{
uid='1372299847',
id='1372299847',
time=1368760855,
changedFields=[feed]
}]
}
But this doesn't tell me what the update exactly was. I have to read that user's feed and see what is the new change and process it. If I get the id, then I can just request for that object and process it rather than reading his feed and getting the changes.
Is there any way to get what exactly was changed(id of the comment or status)?
Facebook doc says that you have to get the actual changeset via Graph API or FQL query. The notification you get tells you only the concerned user's ID.

Categories