: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace WPForms\Integrations\Stripe\Api\Webhooks;
use Stripe\Exception\ApiErrorException;
use WPForms\Db\Payments\Queries;
use WPForms\Integrations\Stripe\Helpers;
use WPForms\Vendor\Stripe\PaymentIntent;
* Webhook invoice.payment_succeeded class.
class InvoicePaymentSucceeded extends Base {
* Handle invoice.payment_succeeded webhook for subscription_cycle billing reason (payment renewal).
* @throws RuntimeException If subscription not found or not updated.
public function handle() {
if ( ! isset( $this->data->billing_reason ) || $this->data->billing_reason !== 'subscription_cycle' ) {
return false; // Webhook handler for Invoice.PaymentSucceeded with reason subscription_cycle not implemented yet.
if ( $this->data->paid !== true ) {
return false; // Subscription not paid, so we are not going to proceed with update.
$db_renewal = ( new Queries() )->get_renewal_by_invoice_id( $this->data->id );
if ( is_null( $db_renewal ) ) {
return false; // Newest renewal not found.
$currency = strtoupper( $this->data->currency );
$amount = $this->data->amount_paid / Helpers::get_decimals_amount( $currency );
wpforms()->get( 'payment' )->update(
'total_amount' => $amount,
'subtotal_amount' => $amount,
'transaction_id' => $this->data->payment_intent,
$this->copy_meta_from_payment_intent( $db_renewal->id );
wpforms()->get( 'payment_meta' )->add_log(
'Stripe renewal was successfully paid. (Payment Intent ID: %1$s)',
$this->data->payment_intent
* Copy meta from payment intent.
* @param int $renewal_id Renewal ID.
* @noinspection PhpMissingParamTypeInspection
private function copy_meta_from_payment_intent( $renewal_id ) {
$payment_intent = PaymentIntent::retrieve( $this->data->payment_intent, Helpers::get_auth_opts() );
} catch ( ApiErrorException $e ) {
if ( ! isset( $payment_intent->charges->data[0]->payment_method_details ) ) {
$this->update_payment_method_details( $renewal_id, $payment_intent->charges->data[0]->payment_method_details );