Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/Gateway/Bank_Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function init() {
$this->id = 'bank';
$this->admin_label = __( 'Bank Payment', 'wp-user-frontend' );
$this->checkout_label = __( 'Bank Payment', 'wp-user-frontend' );
$this->icon = '';
$this->icon = apply_filters( 'wpuf_bank_checkout_icon', WPUF_ASSET_URI . '/images/bank.svg' );
$this->supports_subscription = false;
}

Expand Down
32 changes: 16 additions & 16 deletions Lib/Gateway/Paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private function process_payment_capture( $payment ) {
// Validate breakdown: item_total + tax_total should equal total (within rounding)
$breakdown_total = $subtotal + $tax;
$difference = abs( $breakdown_total - $total_amount );

// If breakdown doesn't add up correctly, recalculate from total
// This handles cases where PayPal returns incorrect breakdown values
if ( $difference > 0.01 ) {
Expand Down Expand Up @@ -386,7 +386,7 @@ private function process_payment_capture( $payment ) {
$total_amount,
$custom_data['type']
);

if ( $recalculated && is_array( $recalculated ) ) {
$subtotal = isset( $recalculated['subtotal'] ) ? floatval( $recalculated['subtotal'] ) : $subtotal;
$tax = isset( $recalculated['tax'] ) ? floatval( $recalculated['tax'] ) : $tax;
Expand Down Expand Up @@ -637,7 +637,7 @@ private function get_access_token() {

$body = json_decode( wp_remote_retrieve_body( $response ), true );

return $body['access_token'];
return ! empty( $body['access_token'] ) ? $body['access_token'] : '';
}

/**
Expand Down Expand Up @@ -1031,7 +1031,7 @@ private function process_subscription_payment( $payment ) {
// Validate breakdown: item_total + tax_total should equal total (within rounding)
$breakdown_total = $subtotal + $tax;
$difference = abs( $breakdown_total - $total_amount );

// If breakdown doesn't add up correctly, recalculate from total
// This handles cases where PayPal returns incorrect breakdown values
if ( $difference > 0.01 ) {
Expand Down Expand Up @@ -1084,7 +1084,7 @@ private function process_subscription_payment( $payment ) {
$total_amount,
'pack'
);

if ( $recalculated && is_array( $recalculated ) ) {
$subtotal = isset( $recalculated['subtotal'] ) ? floatval( $recalculated['subtotal'] ) : $subtotal;
$tax = isset( $recalculated['tax'] ) ? floatval( $recalculated['tax'] ) : $tax;
Expand Down Expand Up @@ -1199,7 +1199,7 @@ public function payment_options( $options ) {
'name' => 'gate_instruct_paypal',
'label' => __( 'PayPal Instruction', 'wp-user-frontend' ),
'type' => 'wysiwyg',
'default' => "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account",
'default' => "Pay via PayPal. You can pay with your credit card if you don't have a PayPal account",
];

// New REST API options
Expand Down Expand Up @@ -1561,7 +1561,7 @@ function ( $value ) {

// Create a plan with base amount (without tax, as tax will be added via subscription override)
$plan_base_amount = isset( $payment_data['breakdown']['item_total'] ) ? $payment_data['breakdown']['item_total'] : $billing_amount;

$plan_id = $this->get_or_create_plan( $pack, $plan_base_amount, $period, $interval, $trial_period_days );

if ( ! $plan_id ) {
Expand Down Expand Up @@ -1592,10 +1592,10 @@ function ( $value ) {
if ( isset( $payment_data['breakdown']['tax_total'] ) && $payment_data['breakdown']['tax_total'] > 0 ) {
$tax_amount = $payment_data['breakdown']['tax_total'];
$subtotal = $payment_data['breakdown']['item_total'] ?? $payment_data['amount'];

// Calculate tax percentage
$tax_percentage = ( $tax_amount / $subtotal ) * 100;

// Add plan override with tax
$subscription_data['plan'] = [
'taxes' => [
Expand Down Expand Up @@ -1788,11 +1788,11 @@ function( $hosts ) {
private function get_or_create_plan( $pack, $amount, $period, $interval, $trial_period_days = 0 ) {
try {
$access_token = $this->get_access_token();

if ( ! $access_token ) {
return false;
}

// Create plan name (tax will be added separately via subscription override)
$plan_name = 'WPUF-' . $pack->post_title . '-' . uniqid();
$plan_id = get_post_meta( $pack->ID, '_paypal_plan_id', true );
Expand Down Expand Up @@ -1822,7 +1822,7 @@ private function get_or_create_plan( $pack, $amount, $period, $interval, $trial_
// Create new plan (tax will be added separately via subscription override)
// Ensure interval_count is at least 1 (PayPal doesn't accept 0 or negative values)
$interval_count = max( 1, intval( $interval ) );

$plan_data = [
'product_id' => $this->get_or_create_product( $pack ),
'name' => $plan_name,
Expand Down Expand Up @@ -1882,7 +1882,7 @@ private function get_or_create_plan( $pack, $amount, $period, $interval, $trial_
// Update the regular billing cycle sequence
$plan_data['billing_cycles'][1]['sequence'] = 2;
}

$response = wp_remote_post(
( $this->test_mode ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com' ) . '/v1/billing/plans',
[
Expand All @@ -1901,7 +1901,7 @@ private function get_or_create_plan( $pack, $amount, $period, $interval, $trial_

$response_code = wp_remote_retrieve_response_code( $response );
$body = json_decode( wp_remote_retrieve_body( $response ), true );


if ( ! isset( $body['id'] ) ) {
throw new \Exception( 'Invalid response from PayPal - no plan ID' );
Expand Down Expand Up @@ -2202,7 +2202,7 @@ public function handle_pending_payment() {
private function handle_subscription_cancelled( $subscription ) {
try {
$subscription_id = isset( $subscription['id'] ) ? $subscription['id'] : 'UNKNOWN';

// Extract custom data
$custom_data = [];
if ( isset( $subscription['custom_id'] ) ) {
Expand Down Expand Up @@ -2255,7 +2255,7 @@ private function handle_subscription_cancelled( $subscription ) {
private function handle_subscription_activated( $subscription ) {
try {
$subscription_id = isset( $subscription['id'] ) ? $subscription['id'] : 'UNKNOWN';

// Extract custom data
$custom_data = [];
if ( isset( $subscription['custom_id'] ) ) {
Expand Down
Loading
Loading