Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/wpforms-.../src/Integrat.../Stripe/Api/Webhooks
File: InvoicePaymentSucceeded.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Integrations\Stripe\Api\Webhooks;
[2] Fix | Delete
[3] Fix | Delete
use RuntimeException;
[4] Fix | Delete
use Stripe\Exception\ApiErrorException;
[5] Fix | Delete
use WPForms\Db\Payments\Queries;
[6] Fix | Delete
use WPForms\Integrations\Stripe\Helpers;
[7] Fix | Delete
use WPForms\Vendor\Stripe\PaymentIntent;
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Webhook invoice.payment_succeeded class.
[11] Fix | Delete
*
[12] Fix | Delete
* @since 1.8.4
[13] Fix | Delete
*/
[14] Fix | Delete
class InvoicePaymentSucceeded extends Base {
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Handle invoice.payment_succeeded webhook for subscription_cycle billing reason (payment renewal).
[18] Fix | Delete
*
[19] Fix | Delete
* @since 1.8.4
[20] Fix | Delete
*
[21] Fix | Delete
* @throws RuntimeException If subscription not found or not updated.
[22] Fix | Delete
*
[23] Fix | Delete
* @return bool
[24] Fix | Delete
*/
[25] Fix | Delete
public function handle() {
[26] Fix | Delete
[27] Fix | Delete
if ( ! isset( $this->data->billing_reason ) || $this->data->billing_reason !== 'subscription_cycle' ) {
[28] Fix | Delete
return false; // Webhook handler for Invoice.PaymentSucceeded with reason subscription_cycle not implemented yet.
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
if ( $this->data->paid !== true ) {
[32] Fix | Delete
return false; // Subscription not paid, so we are not going to proceed with update.
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
$db_renewal = ( new Queries() )->get_renewal_by_invoice_id( $this->data->id );
[36] Fix | Delete
[37] Fix | Delete
if ( is_null( $db_renewal ) ) {
[38] Fix | Delete
return false; // Newest renewal not found.
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
$currency = strtoupper( $this->data->currency );
[42] Fix | Delete
$amount = $this->data->amount_paid / Helpers::get_decimals_amount( $currency );
[43] Fix | Delete
[44] Fix | Delete
wpforms()->get( 'payment' )->update(
[45] Fix | Delete
$db_renewal->id,
[46] Fix | Delete
[
[47] Fix | Delete
'total_amount' => $amount,
[48] Fix | Delete
'subtotal_amount' => $amount,
[49] Fix | Delete
'status' => 'completed',
[50] Fix | Delete
'transaction_id' => $this->data->payment_intent,
[51] Fix | Delete
]
[52] Fix | Delete
);
[53] Fix | Delete
[54] Fix | Delete
$this->copy_meta_from_payment_intent( $db_renewal->id );
[55] Fix | Delete
[56] Fix | Delete
wpforms()->get( 'payment_meta' )->add_log(
[57] Fix | Delete
$db_renewal->id,
[58] Fix | Delete
sprintf(
[59] Fix | Delete
'Stripe renewal was successfully paid. (Payment Intent ID: %1$s)',
[60] Fix | Delete
$this->data->payment_intent
[61] Fix | Delete
)
[62] Fix | Delete
);
[63] Fix | Delete
[64] Fix | Delete
return true;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Copy meta from payment intent.
[69] Fix | Delete
*
[70] Fix | Delete
* @since 1.8.4
[71] Fix | Delete
*
[72] Fix | Delete
* @param int $renewal_id Renewal ID.
[73] Fix | Delete
*
[74] Fix | Delete
* @noinspection PhpMissingParamTypeInspection
[75] Fix | Delete
*/
[76] Fix | Delete
private function copy_meta_from_payment_intent( $renewal_id ) {
[77] Fix | Delete
[78] Fix | Delete
try {
[79] Fix | Delete
$payment_intent = PaymentIntent::retrieve( $this->data->payment_intent, Helpers::get_auth_opts() );
[80] Fix | Delete
} catch ( ApiErrorException $e ) {
[81] Fix | Delete
$payment_intent = null;
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
if ( ! isset( $payment_intent->charges->data[0]->payment_method_details ) ) {
[85] Fix | Delete
return;
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
$this->update_payment_method_details( $renewal_id, $payment_intent->charges->data[0]->payment_method_details );
[89] Fix | Delete
}
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function