ordersRepository = $ordersRepository; } /** * Refunds the payment when the donation is marked as refunded * * @since 2.9.0 * * @param int $donationId * * @throws Exception */ public function refundPayment($donationId) { if ( ! $this->isAdminOptInToRefundPaymentOnPayPal()) { return; } $payPalPaymentId = give_get_payment_transaction_id($donationId); $paymentGateway = give_get_payment_gateway($donationId); $newDonationStatus = give_clean($_POST['give-payment-status']); if ('refunded' !== $newDonationStatus || PayPalCommerce::GATEWAY_ID !== $paymentGateway) { return; } try { $this->ordersRepository->refundPayment($payPalPaymentId); } catch (Exception $ex) { wp_safe_redirect( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id={$donationId}&paypal-error=refund-failure" ) ); exit(); } } /** * show Paypal Commerce payment refund failure notice. * * @since 2.9.0 */ public function showPaymentRefundFailureNotice() { if ( ! isset($_GET['paypal-error']) || 'refund-failure' !== $_GET['paypal-error']) { return; } give('notices')->register_notice( [ 'id' => 'give-paypal-commerce-refund-failure', 'type' => 'warning', 'show' => true, 'description' => sprintf( '%1$s %2$s %3$s%5$s%6$s', esc_html__('PayPal Donations:', 'give'), esc_html__('We were unable to process refund.', 'give'), esc_html__('Please ', 'give'), admin_url('edit.php?post_type=give_forms&page=give-tools&tab=logs'), esc_html__('check log', 'give'), esc_html__(' for detailed information.', 'give') ), ] ); } /** * This function will display field to opt for refund. * * @since 2.5.0 * * @param int $donationId Donation ID. * * @return void */ public function optInForRefundFormField($donationId) { if (PayPalCommerce::GATEWAY_ID !== give_get_payment_gateway($donationId)) { return; } ?>