Spinbox Posted April 2 Share Posted April 2 I need to include Stripe's Charge ID to invoices. This way some accounting software can relate the payment to the invoice via Stripe. On successfull payment (Order complete); Inside the Stripe Payment Processer I found that 'isSuccessfulPaymentCapture($response, $options = [])' $response is returning it's latest_charge (the charge_id). How can I save this to the order? 1 Link to comment Share on other sites More sharing options...
kongondo Posted April 4 Share Posted April 4 Hi @Spinbox, I have made this hookable so you have access to $response and $options. However, we have no dedicated field for saving this value. You could add a text field to your order template. Then save the latest_charge value to that field. This way, it stays together with the order and you can easily retrieve and add it to your invoices. Does this make sense or you need example code? Thanks. 1 Link to comment Share on other sites More sharing options...
Spinbox Posted April 4 Author Share Posted April 4 Thank you for the pointers, I feel like a newb sometimes, let me cook something up. Link to comment Share on other sites More sharing options...
Spinbox Posted April 23 Author Share Posted April 23 I have managed to save the charge id to the order. For this to work I needed to make captureOrder hookable. This is probably not the right way tough.. $wire->addHookAfter('PadloperProcessOrder::captureOrder', function(HookEvent $event) { $paymentIntent = $event->return; $orderId = $paymentIntent->metadata->reference_id; if ($paymentIntent && $paymentIntent->status === 'succeeded') { $chargeId = $paymentIntent->latest_charge; // Load the order page using the order ID and save the charge ID $orderPage = wire()->pages->get("template=padloper-order, id={$orderId}"); if ($orderPage->id) { $orderPage->of(false); $orderPage->set('stripe_charge_id', $chargeId); $orderPage->save(); } } }); 1 Link to comment Share on other sites More sharing options...
kongondo Posted May 5 Share Posted May 5 Hey @Spinbox, That's fine. In Padloper 009 you could also do it like this (saves you making captureOrder hookable; will get overwritten with upgrades unless I make it hookable here as well): <?php namespace ProcessWire; $wire->addHookAfter('PadloperProcessOrder::isSuccessfulPaymentCaptureHook', function (HookEvent $event) { $paymentIntent = $event->arguments('response'); $orderId = $paymentIntent->metadata->reference_id; // ALTERNATIVELY // $options = $event->arguments('options'); // $orderId = $options['expected_order_id']; if ($paymentIntent && $paymentIntent->status === 'succeeded') { $chargeId = $paymentIntent->latest_charge; // Load the order page using the order ID and save the charge ID $orderPage = wire()->pages->get("template=padloper-order, id={$orderId}"); if ($orderPage->id) { $orderPage->of(false); $orderPage->set('stripe_charge_id', $chargeId); $orderPage->save('stripe_charge_id'); } } }); Hope this helps. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now