how to get the Fee Amount for paypal - java

I am currently looking at a system that implements the PayPal api. As a part of this I need to get the feeAmt() which is the fee that is paid to paypal for processing the payment.
From the documentation that I have looked at it appears that I have to implement the getExpressCheckoutDetailsReq() method in order to get the information that I want however no matter what I have tried I am struggling to do this. I should also let you know that I am currently developing my application using Java so using this is going to be best.
If any more explanation is needed please don't hesitate to ask and I will do my best to amend the post :)

GetExpressCheckoutDetails does not include the fee because at that point no payment has been made yet. That's the 2nd of 3 calls for Express Checkout, and until the final call is made there is no fee.
The fee amount would actually come in that final call's response: DoExpressCheckoutPayment. It will come in the PAYMENTINFO_n_FEEAMT parameter, where n is the number of the payment (0,1,2,etc.) Most likely it'll be 0 unless you're working with parallel payments.
Alternatively, you can use Instant Payment Notification (IPN) to get details about transactions, including the fee, in real-time when transactions are completed on your PayPal account.
Yet another option would be to use the GetTransactionDetails API to pull data for an individual transaction which would include the fee in a FEEAMT parameter. Maybe that's the one you were initially thinking of..??

Related

queryPurchases() vs queryPurchaseHistoryAsync() in order to 'restore' functionality?

I'm using the Play Billing Library in order to trigger and manage purchases which in turn unlocked extra functionality within an app. This part is working.
However, what is the best way to 'restore' purchases. Say for example someone who has bought the app buys a new phone. Logs in to the Play Store, downloads my app and then finds that the payment screen to 'upgrade' is being displayed. iOS has a specific method for this but I'm not aware of one for Android.
My thoughts are to query the Play Store and confirm whether the account has previously SUCCESSFULLY purchased the item, if so then I will call the local upgrade function within the app.
It appears there are two similar methods. But which one should I used in this scenario? Where a user has either wiped their phone or bought a new one?
queryPurchases()? Or queryPurchaseHistoryAsync()?
You should use queryPurchases. That gives you all the current active (non-consumed, non-cancelled, non-expired) purchases for each SKU.
queryPurchaseHistoryAsync won't do what you need because it will only give you a list of the most recent purchases for each SKU. They may have expired, been cancelled or been consumed, and there's no way to tell. Therefore this response can't be used to tell what purchases to apply in your app.
So far as I can see, the only valid use for queryPurchaseHistoryAsync is to provide a user with a list of their purchase history. It's a bit of an oddball.
Note also: queryPurchases is synchronous so in most cases it needs to be run in some kind of background worker thread. I run mine in an AsyncTask.
Per documentation queryPurchases uses the Play Store app cache to get the results while queryPurchaseHistoryAsyncactually checks the Purchase AP for the most recent purchases. So, in your case you should check the Asyncmethod.
queryPurchases
Get purchases details for all the items bought within your app. This method uses a cache of Google Play Store app without initiating a network request.
queryPurchaseHistoryAsync
Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.
Also, make sure to check the documentation. It recommends to Cache purchase details on your servers.
https://developer.android.com/google/play/developer-api.html#practices
I know it's a bit late, but I just discovered this myself. Sharing my answer for others to benefit.
So I learned that queryPurchases() is cached locally on your device, but is updated when you call queryPurchaseHistoryAsync()
I discovered from this Stackoverflow answer here
So my solution, is when wanting to restore a purchase on a new device, or a fresh install of my app. Call queryPurchaseHistoryAsync() Then in the callback onPurchaseHistoryResponse() call queryPurchases() and look within the List<Purchase> from the PurchasesResult for the purchase status of any of the user's past purchases.
If there's an expected purchase your app can grant the entitlements of their past purchase.
The documentation has been updated for the latest versions of BillingClient. queryPurchases() is deprecated. Also note that queryPurchases() only ever returned purchases made by the current device, so that method will not inform your scenario of a new wiped phone. To get accurate information use the async calls.
queryPurchasesAsync() will return all active subscription and unconsumed one-time Purchase objects for the sku type provided. It gets the purchases from the local Play Services cache, so there are no guarantees the cache will contain purchases from another device in your "new phone" scenario, and no guarantees the cache will yet be current in your "wiped phone" scenario.
queryPurchaseHistoryAsync() will make a network request and return the most recent PurchaseHistory object for each sku matching the provided sku type, even if cancelled or consumed.
Also, to perform the upgrade call launchBillingFlow() with the appropriate BillingFlowParams and BillingFlowParams.SubscriptionUpdateParams for the sku you now know to be purchased.

Design to manage paid subscription to services in an application?

Let's say I have a hypothetical paid application like stackoverflow. The application allows a user to do two things:
Post a question
Post an answer
This application charges $20 to buy a plan which allows posting 10 questions and 10 answers.
Technically, both the actions are exposed through completely different interfaces
interface Questions {
postQuestion(String question);
}
interface Answers {
postAnswer(int questionId, String answer);
}
Both the services are accessible over web through different controllers. I need to keep track of how many questions and answers the user has posted, so that I can ask them to make a new purchase when the limit is reached, without delegating this task to the services.
For instance in Java, I need something like a map like Map<Method,Integer>, which keeps track of how many times each allowed method was successfully invoked. And, maintain this map by intercepting the calls to these services. This Map will also require database storage.
Thanks!
In your Customer DB you can add a answerCounter and a questionCounter.
When the customer registered set those value to 10.
Each time a service is called first check if the customer is allowed to call it by checking if answerCounter or questionCounter (depending on the request) is higher than 0.
If the customer is allowed to post the answer/question then decrement the answerCounter or questionCounter by 1.
If the customer paid a new pack increase those value by or to 10.

paypal transaction value doesn't show

I'm following a tutorial from the paypal documentation to make it possible to pay through paypal. Here is the code I'm trying to implement. However when I run the code it won't show me the amount that is supposed to be payed while it is set in the transaction through the code.
Does anyone know what needs to happen for this to work? Is the example either not complete or not up to date?
I figured out what was wrong. For the transaction to work something additional must be added to the paypal link.
When returned from paypal the link you have to navigate to to pay looks like this
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-3WC762911Y9384932
however an additional parameter is needed for paypal to show the price that was set. To do so the following parameter needs to be added &useraction=commit
The entire link would look like this
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=EC-3WC762911Y9384932

Braintree - Android SDK: new credit card or existing one?

I'm new to the Android+Braintree world. At the moment I'm using the Drop-In interface.
What I want to do is the following
"If the user is creating/adding a new card, ask him if he wants to save
credit card information".
I need this info because later I will set the storeInVaultOnSuccess option in the transaction's params accordingly.
Now, it seems that there is no way to insert an element in the drop-in GUI to understand if the user wants to save these data or not.
Fine, so I'm going to add an additional step just after the drop-in interface in which I'm only going to ask the user if he wants to save the credit card data or not.
But the problem is that I don't want to ask this question if he choose an already existent credit card, so I need to know if he created a new card or if he selected an existent one.
Is there a way to perform this task (or is there a better alternative)?
WHAT I'VE ALREADY TRIED:
I've tried to see all the information given in the onActivityResult method, more specifically the content of the Intent given as the 3rd parameter.
What I have is, of course, the EXTRA_PAYMENT_METHOD_NONCE, and then the EXTRA_PAYMENT_METHOD (type com.braintreepayments.api.models.Card), but looking at the code of Card.java I'm not able to understand how to retrieve (if possible) this kind of information.
Thanks in advance.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
The Drop-In UI doesn't support that workflow because at the time of entry the Drop-In automatically vaults the credit card and just provides the nonce (which doesn't contain any information about the card to the client for PCI reasons). In other words, storeInVaultOnSuccess won't apply since it's already there.
As you say, the way to get around this - while still using the Drop-In - would be to keep a reference to the payment method used in the transaction and ask after the transaction goes through. You can get this by examining the response object:
String payment_method_token = "";
TransactionRequest request = new TransactionRequest()
.amount(new BigDecimal("100.00"));
.paymentMethodNonce(nonceFromTheClient);
Result<Transaction> result = gateway.transaction().sale(request);
Transaction transaction = result.getTarget();
if (transaction.getPaymentInstrumentType().equals(PaymentInstrumentType.CREDIT_CARD){
payment_method_token = transaction.getCreditCard.getToken();
}
// ... other payment method types that you support
However, as you say, this is more complicated. You would have to make some selection based on:
a) when the payment method was created (using createdAt), or
a) comparing the arrays of payment methods before and after the checkout experience
This sort of flow really pushes the limits of the Drop-In, and these sorts of constraints often move developers to switch to a custom integration. In that case you would collect their preference - whether they want it stored - as they enter their credit card information.

FacebookCredits - add credits to test users

I'm looking for another answer than the one stated here. I want to see the credits "transfered" in my app. Insights but with test users transactions, in order to ensure that callback has no mistakes. I'm afraid it can't be done, but if someone has another option, that could be helpful as well.
Your only options are to use testers, and live with the fact that their transactions won't appear in the payout reports, or use real credits and real money

Categories