PayPal API List transactions for subscription: Pagination not working - paypal

According to the docs it should be possible to use pagination.
I call the endpoint with my subscription id and as a startdate I choose 01.01.2010 and enddate I choose today.
(/v1/billing/subscriptions/{id}/transactions)
I get returned only 30 items and I also do not see in my response the "total_items" value or anything else related to pages.
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions
Do I miss something or is this just another bug in paypal?
My goal is it to get all transactions for a specific subscription.

Related

Handling Stripe Checkout flow and Firestore update, without a race condition?

I have a plan as to how I would go about doing this and wanted to know if I am headed in the right direction or if there is a better way altogether.
From Firestore Documentation:
In the case of a concurrent edit, Cloud Firestore runs the entire transaction again. For example, if a transaction reads documents and another client modifies any of those documents, Cloud Firestore retries the transaction. This feature ensures that the transaction runs on up-to-date and consistent data.
I have a react front end and node express backend.
Front end sends request to create a checkout session.
In the backend I simply parse the request with the required data then send it to Stripe and receive Stripe's response.
Then for each product P in the customers cart:
We create a Firebase transaction in which:
- get (P) from Firestore
- if P.stock >= 1 then decrement by one and send the redirect uri from stripe to frontend
- else Item is out of stock send custom Failed payment response to front end
Now if two people are trying to purchase the same item and we only have 1 of that item in stock, only one person will be able to complete the payment flow. Is that correct?
I am adding this image to better explain what the flow would look like:
Flow Diagram
To avoid such race condition you must trigger events earlier at a point that will take more time for your customer to start the purchase process than the longest API call scenario.
If you have a basket system, you could simply decrement the stock as soon as the item is added to it. Then when your basket is deleted after the purchase do nothing to the stock else after you make the basket expire after a certain time increment back your stock.
You can still create such a basket-like system even without the user seeing it in the front end. When the purchase succeeds, retrieve your basket doc id from the session metadata and delete it. If you don't delete it after a payment succeeds, that is, before expiration, increment your stock back.
I hope my answer is not too confusing, share the implementation you're heading for, I curious!

PayPal Subscriptions: validating success on a server

I apologize in advance for this question, as its probably rather silly, but I really can not find any answers elsewhere.
My current goal is to integrate a subscription to my website, that allows for a user to have access to certain parts of the site.
I've watched a few videos on it, but it leaves me open ended with some questions.
PayPal allows you to manually create a subscription plan at https://www.paypal.com/billing/plans. When you create a plan here, it gives you the code you need to get the pay pal sub buttons to display on the page. Users can then use them to create the subscription. This is great. However, I have found now way to validate the results of the transaction. My goal would be that if the user was successful, I would be able to retrieve data via the API, that says it was successful, and I could then store than information in my database, and grant them access. Does anyone know how to get the data from the manually created facebook plans?
I did watch a video that had you do everything from your website (you create it all within your own code), the end result however sent everything through $_GET variables in the url. I feel like having this data exposed could result in the manipulation of the subscription, and grant it to users who were unsuccessful in creating a subscription.
I have no problem doing all of the coding to make this work, but I really want to make sure I do it the best possible way.
There is a few way to do it. By setting up a webhook and listen to paypal success notification and react to it. By using the Paypal Subscription API. Or a combination of both.
As you are using the paypal button you will have the onApprove function which will trigger upon user confirming the subscription. You can query the subscription data with:
onApprove={async (data: any, actions: any) => {
const detailedSubscriptionData = await actions.subscription.get()
// activate subscription on your side by sending it to your backend
...
// etc.
}}
Inside the data you have queried above, there will be a paypal transaction id (I-....) that is unique for each transaction, as well as your product id (plan_id). You can now do the following for verification on your backend:
Check if there is already a subscription (from another customer) on your side with that paypal transaction id
Check for the plan_id
Queried the API Subscription Details with the paypal transaction id and check for status, etc. as well as matching of plan_id
Keep in mind that for using the API you will have to queried for an access-token which in turn required you to have Developer App Setup following these steps.

Paypal - Get the order identifier out of transaction identifier

I could not find info in the documentation on how to grab an order id out of the capture id that I receive from the daily transaction detail report. The only way I found was to check the links field in the capture after the capture gets the request, however, that does not seem like the best way to do it.
Does anyone know how to achieve it directly?
If you are using the Orders V2 API, the Order ID is only used during checkout approval. It is not persisted after transaction creation, and looking up captured payment details with the transaction/capture id: https://developer.paypal.com/docs/api/payments/v2/#captures_get , will not return the Order ID used during checkout, since it is not useful for anything at that point.

GET transaction information from a specific PayPal transaction using Webhooks and PayPal API in Zapier

UPDATE: After troubleshooting on postman, I've found that start_date and end_date are nessesary fields. Everything now works fine on postman with 200 code. However I am still getting a 400 error on zapier...
I've managed to POST my API credentials and generate an access-token from the previous step in my zap sequence using a Webhook. I then used this token in a GET Webhook in the next step to try and retrieve transaction information (PayPal processing fee, etc...) using transaction_id and fields queries. The transaction ID I am using is being pulled from an actual Woocommerce order on our store, where the customer decided to use PayPal (I've also searched the ID in paypal and it is valid).
The reason I'm doing this is to try and pull extra information from PayPal- Such as payment processing fees about the transaction that Woocommerce does not provide through their app on Zapier.
Unfortunately I am seeing the following error 'The app returned "Invalid request - see details."'
I suspect it is because I am calling for the information incorrectly. In my mind, I am using transaction_id as the unique identifier for the specific transaction, and fields to retrieve all information regarding the transaction.
Error code in Zapier: "Status Code 400 Bad Request" - PayPal docs state: "INVALID_REQUEST. Request is not well-formed, syntactically incorrect, or violates schema"
Update: If you use this method to pull transaction information, you will need to set a delay long enough where the activity time on your paypal dashboard switches from a time to a date (meaning it is the next day). If you don't do this, no important information will be pulled.
I've figured it out. If anyone has a similar issue, set it up like this (probably use more dynamic dates though):

Payments Callback URL not being call after new local currency changes

After switching to the new Facebook local currency API the process is working, but
my server is not involve in the process so i really don't know if the user bought coins cause the payment callback URL is not being called now (using static payment).
I tried to use real time update to get Facebook data but can make it work, what is the best practice to involve the server in the process so it will be aware of the purchase?
I prefer for security reasons to get the update from Facebook and not from my client.
Ok after searching a log i found the solution
There are two primary methods through which you are notified of the outcome of the purchase, and a further method by which you can verify any payment information.
Firstly, Facebook will return details of the order via a JavaScript callback. The data sent to this callback includes:
payment_id, which uniquely identifies the transaction.
quantity, which indicates the amount of the item which was sold.
request_id, optionally, the developer can provide their own unique identification for the transaction when calling our Javascript SDK to render the payment dialog. This value is then returned upon purchase completion.
status, which indicates the current state of the transaction, i.e. 'pending', 'completed', 'failed' etc.
Secondly, Facebook will issue a realtime update notifying the developer that a new order has completed. The developer can subscribe to the payment_object callback to track order completions, using the payment_id as the unique identity parameter for each transaction.
Thirdly, at any time, the payment_id can be used to verify details of a transaction via the Graph API. Details such as the associated user_id, updated_time and amount can be queried, using the payment_id. The Graph API will also allow you to access further details including any refunds or disputes associated with the transaction.
If for some reason both the JavaScript callback and the realtime update fail and you do not receive the payment_id, we also allow you to query the Graph API using the optional request_id parameter, which can be specified by the developer when invoking the Facebook payment dialog.
please refer to:
https://developers.facebook.com/docs/concepts/payments/
and to:
https://developers.facebook.com/docs/howtos/payments/fulfillment/#rtu