id : $order->get_id();
$payment_method = $old_wc ? $order->payment_method : $order->get_payment_method();
$paypal_status = $old_wc ? get_post_meta( $order_id, '_paypal_status', true ) : $order->get_meta( '_paypal_status', true );
// bail if the order wasn't paid for with this gateway
if ( 'ppec_paypal' !== $payment_method || 'pending' !== $paypal_status ) {
return $actions;
}
if ( ! is_array( $actions ) ) {
$actions = array();
}
$actions['ppec_capture_charge'] = esc_html__( 'Capture Charge', 'woocommerce-gateway-paypal-express-checkout' );
return $actions;
}
/**
* Force zero decimal on specific currencies.
*/
public function force_zero_decimal() {
$settings = wc_gateway_ppec()->settings;
if ( $settings->currency_has_decimal_restriction() ) {
update_option( 'woocommerce_price_num_decimals', 0 );
update_option( 'wc_gateway_ppce_display_decimal_msg', true );
}
}
/**
* Show decimal warning.
*/
public function show_decimal_warning() {
if ( get_option( 'wc_gateway_ppce_display_decimal_msg', false ) ) {
?>
id : $order->get_id();
$this->capture_payment( $order_id );
return true;
}
/**
* Capture payment when the order is changed from on-hold to complete or processing
*
* @param int $order_id
*/
public function capture_payment( $order_id ) {
$order = wc_get_order( $order_id );
$old_wc = version_compare( WC_VERSION, '3.0', '<' );
$payment_method = $old_wc ? $order->payment_method : $order->get_payment_method();
if ( 'ppec_paypal' === $payment_method ) {
$trans_id = get_post_meta( $order_id, '_transaction_id', true );
$trans_details = wc_gateway_ppec()->client->get_transaction_details( array( 'TRANSACTIONID' => $trans_id ) );
if ( $trans_id && $this->is_authorized_only( $trans_details ) ) {
$order_total = $old_wc ? $order->order_total : $order->get_total();
$params['AUTHORIZATIONID'] = $trans_id;
$params['AMT'] = floatval( $order_total );
$params['COMPLETETYPE'] = 'Complete';
$result = wc_gateway_ppec()->client->do_express_checkout_capture( $params );
if ( is_wp_error( $result ) ) {
$order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-paypal-express-checkout' ) . ' ' . $result->get_error_message() );
} else {
update_post_meta( $order_id, '_paypal_status', ! empty( $trans_details['PAYMENTSTATUS'] ) ? $trans_details['PAYMENTSTATUS'] : 'completed' );
if ( ! empty( $result['TRANSACTIONID'] ) ) {
update_post_meta( $order_id, '_transaction_id', $result['TRANSACTIONID'] );
}
$order->add_order_note( sprintf( __( 'PayPal Checkout charge complete (Charge ID: %s)', 'woocommerce-gateway-paypal-express-checkout' ), $trans_id ) );
}
}
}
}
/**
* Checks to see if the transaction can be captured
*
* @param array $trans_details
*/
public function is_authorized_only( $trans_details = array() ) {
if ( ! is_wp_error( $trans_details ) && ! empty( $trans_details ) ) {
if ( 'Pending' === $trans_details['PAYMENTSTATUS'] && 'authorization' === $trans_details['PENDINGREASON'] ) {
return true;
}
}
return false;
}
/**
* Cancel authorization
*
* @param int $order_id
*/
public function cancel_payment( $order_id ) {
$order = wc_get_order( $order_id );
$old_wc = version_compare( WC_VERSION, '3.0', '<' );
$payment_method = $old_wc ? $order->payment_method : $order->get_payment_method();
if ( 'ppec_paypal' === $payment_method ) {
$trans_id = get_post_meta( $order_id, '_transaction_id', true );
$trans_details = wc_gateway_ppec()->client->get_transaction_details( array( 'TRANSACTIONID' => $trans_id ) );
if ( $trans_id && $this->is_authorized_only( $trans_details ) ) {
$params['AUTHORIZATIONID'] = $trans_id;
$result = wc_gateway_ppec()->client->do_express_checkout_void( $params );
if ( is_wp_error( $result ) ) {
$order->add_order_note( __( 'Unable to void charge!', 'woocommerce-gateway-paypal-express-checkout' ) . ' ' . $result->get_error_message() );
} else {
$order->add_order_note( sprintf( __( 'PayPal Checkout charge voided (Charge ID: %s)', 'woocommerce-gateway-paypal-express-checkout' ), $trans_id ) );
}
}
}
}
/**
* Get admin URL for this gateway setting.
*
* @deprecated
*
* @return string URL
*/
public function gateway_admin_url( $gateway_class ) {
_deprecated_function( 'WC_Gateway_PPEC_Admin_Handler::gateway_admin_url', '1.0.4', 'wc_gateway_ppec()->get_admin_setting_link' );
return wc_gateway_ppec()->get_admin_setting_link();
}
/**
* Maybe redirect to wc_gateway_ppec_with_paypal from PayPal standard
* checkout settings.
*
* @return void
*/
public function maybe_redirect_to_ppec_settings() {
if ( ! wc_gateway_ppec()->settings->enabled ) {
return;
}
if ( empty( $_GET['tab'] ) || empty( $_GET['section'] ) ) {
return;
}
if ( 'checkout' === $_GET['tab'] && 'wc_gateway_paypal' === $_GET['section'] ) {
$redirect = add_query_arg( array( 'section' => 'wc_gateway_ppec_with_paypal' ) );
wp_safe_redirect( $redirect );
}
}
/**
* Reset API credentials if merchant clicked the reset credential link.
*
* When API credentials empty, the connect button will be displayed again,
* allowing merchant to reconnect with other account.
*
* When WooCommerce Branding is active, this handler may not be invoked as
* screen ID may evaluates to something else.
*
* @since 1.2.0
*/
public function maybe_reset_api_credentials() {
if ( empty( $_GET['reset_ppec_api_credentials'] ) ) {
return;
}
if ( empty( $_GET['reset_nonce'] ) || ! wp_verify_nonce( $_GET['reset_nonce'], 'reset_ppec_api_credentials' ) ) {
return;
}
$settings = wc_gateway_ppec()->settings;
$env = $settings->_environment;
if ( ! empty( $_GET['environment'] ) ) {
$env = $_GET['environment'];
}
$prefix = 'sandbox' === $env ? 'sandbox_' : '';
foreach ( array( 'api_username', 'api_password', 'api_signature', 'api_certificate' ) as $key ) {
$key = $prefix . $key;
$settings->{$key} = '';
}
// Save environment too as when it switches to another env and merchant
// click the reset they'd expect to save the environment too.
$settings->environment = 'sandbox' === $env ? 'sandbox' : 'live';
$settings->save();
wp_safe_redirect( wc_gateway_ppec()->get_admin_setting_link() );
}
/**
* Displays the PayPal fee and the net total of the transaction without the PayPal charges
*
* @since 1.6.6
*
* @param int $order_id
*/
public function display_order_fee_and_payout( $order_id ) {
$order = wc_get_order( $order_id );
$old_wc = version_compare( WC_VERSION, '3.0', '<' );
$payment_method = $old_wc ? $order->payment_method : $order->get_payment_method();
$paypal_fee = wc_gateway_ppec_get_transaction_fee( $order );
$order_currency = $old_wc ? $order->order_currency : $order->get_currency();
$order_total = $old_wc ? $order->order_total : $order->get_total();
if ( 'ppec_paypal' !== $payment_method || ! is_numeric( $paypal_fee ) ) {
return;
}
$net = $order_total - $paypal_fee;
?>
|
|
|
- $order_currency ) ); ?>
|
|
|
|
$order_currency ) ); ?>
|