<p>I use commerce for subscriptions. We design a twig page to show subscriber's payment history.</p>
<p>For some reasons, the very last purchase don't show as we need to perform a &quot;refresh-payments&quot; (From commerce\controllers\SubscriptionsController actionRefreshPayments function) exactly like the one on CP. (See image).</p>
<p>But obviously, we want the user to see immediately his latest purchase without adding such a button. I don't understand where are actual data located and what makes the refresh button to get the latest purchase available from now on, but at least I'd like to perform the refresh before the page is shown.</p>
<p>So before searching any deeper, I wonder if there's a way I can perform that call in twig. (I'm a back-end php guy, learning how to reproduce behavior in twig).
<a href="https://i.sstatic.net/jtpDF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jtpDF.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2022-01-06T20:32:39.530Z
I may not understand the use case exactly—but I think the issue might just be a product of how Subscriptions work in Stripe? Invoices are by nature asynchronous, so you can't really "know" when a payment or invoice will show up here… as such, when someone signs up, they may not see the first payment until a webhook is emitted, at which point Commerce will log it. "Refreshing" before that happens I don't think will guarantee a new invoice will show up! Can you confirm that you have webhooks configured?
August Miller
CC BY-SA 4.0
2022-01-06T20:41:27.267Z
At this point, we manage to get a subscription and send it to Stripe. I goes thru. But if a user wants to immediately see it in the history, we need to add a form with a button and add this hidden field ( `name="action" value="commerce/subscriptions/refresh-payments" `).
If I look at the controller, what it does, it find the Gateway and perform a refreshPaymentHistory to this Gateway. I want to perform it before I show the page, the get the latest lines from Stripe.
Sylvain Tremblay
CC BY-SA 4.0
2022-01-07T03:25:18.707Z
Sure, that much makes sense! Unfortunately, way the archaic payment processing technology that Stripe (mostly) abstracts away works, the assumption has to be that transaction settlement may take an indefinite amount of time (i.e. 1 second or 1 hour). 3D Secure and other auth processes further complicate this—but it all boils down to there being no guarantee _even if you manually call `refreshPayments`_ that the expected transaction will be posted yet. 
August Miller
CC BY-SA 4.0
2022-01-07T05:31:33.497Z
…that said—looks like Commerce exposes this via the gateway? Assuming you have a reference to the Subscription already, you might try: `{% do subscription.gateway.refreshPaymentHistory(subscription) %}`
August Miller
CC BY-SA 4.0
2022-01-07T13:56:55.260Z
@AugustMiller Thank you. That's exactly what I needed. And thanks for all clarification about settlement time, I will keep this in mind.
Sylvain Tremblay
<plugin-craftcommerce><commerce-subscriptions>
Twig call to get REFRESHED payments
# Twig call to get REFRESHED payments

(Asked by: username_0 on 2022-01-06)

I use commerce for subscriptions. We design a twig page to show subscriber's payment history.

For some reasons, the very last purchase don't show as we need to perform a "refresh-payments" (From commerce\controllers\SubscriptionsController actionRefreshPayments function) exactly like the one on CP. (See image).

But obviously, we want the user to see immediately his latest purchase without adding such a button. I don't understand where are actual data located and what makes the refresh button to get the latest purchase available from now on, but at least I'd like to perform the refresh before the page is shown.

So before searching any deeper, I wonder if there's a way I can perform that call in twig. (I'm a back-end php guy, learning how to reproduce behavior in twig).
[![enter image description here](https://i.sstatic.net/jtpDF.png)](https://i.sstatic.net/jtpDF.png)

**Tags:** plugin-craftcommerce, commerce-subscriptions

> **Comments:**
> **username_1**: I may not understand the use case exactly—but I think the issue might just be a product of how Subscriptions work in Stripe? Invoices are by nature asynchronous, so you can't really "know" when a payment or invoice will show up here… as such, when someone signs up, they may not see the first payment until a webhook is emitted, at which point Commerce will log it. "Refreshing" before that happens I don't think will guarantee a new invoice will show up! Can you confirm that you have webhooks configured?  
> **username_0**: At this point, we manage to get a subscription and send it to Stripe. I goes thru. But if a user wants to immediately see it in the history, we need to add a form with a button and add this hidden field ( `name="action" value="commerce/subscriptions/refresh-payments" `). If I look at the controller, what it does, it find the Gateway and perform a refreshPaymentHistory to this Gateway. I want to perform it before I show the page, the get the latest lines from Stripe.  
> **username_1**: Sure, that much makes sense! Unfortunately, way the archaic payment processing technology that Stripe (mostly) abstracts away works, the assumption has to be that transaction settlement may take an indefinite amount of time (i.e. 1 second or 1 hour). 3D Secure and other auth processes further complicate this—but it all boils down to there being no guarantee _even if you manually call `refreshPayments`_ that the expected transaction will be posted yet.   
> **username_1**: …that said—looks like Commerce exposes this via the gateway? Assuming you have a reference to the Subscription already, you might try: `{% do subscription.gateway.refreshPaymentHistory(subscription) %}`  
> **username_0**: @AugustMiller Thank you. That's exactly what I needed. And thanks for all clarification about settlement time, I will keep this in mind.  

---

## 0 answers

