gateway ) { return; } $mode = ( 'live' === $payment->mode ) ? API::MODE_LIVE : API::MODE_SANDBOX; try { $api = new API( $mode ); } catch ( Exceptions\Authentication_Exception $e ) { // If we don't have credentials. return; } $label = __( 'Refund Transaction in PayPal', 'easy-digital-downloads' ); ?> ID ) ) { return; } if ( 'paypal_commerce' !== $payment->gateway || empty( $_POST['edd-paypal-commerce-refund'] ) ) { return; } // Payment status should be coming from "publish" or "revoked". // @todo In 3.0 use `edd_get_refundable_order_statuses()` if ( ! in_array( $payment->old_status, array( 'publish', 'complete', 'revoked', 'edd_subscription' ) ) ) { return; } // If the payment has already been refunded, bail. if ( $payment->get_meta( '_edd_paypal_refunded', true ) ) { return; } // Process the refund. try { refund_transaction( $payment ); } catch ( \Exception $e ) { edd_insert_payment_note( $payment->ID, sprintf( /* Translators: %s - The error message */ __( 'Failed to refund transaction in PayPal. Error Message: %s', 'easy-digital-downloads' ), $e->getMessage() ) ); } }