@@ -255,17 +255,23 @@ private function prepare_paypal_context( $data, $membership, $member_email, $sub
255255 $ membership_process = urm_get_membership_process ( $ member_id );
256256 $ is_renewing = ! empty ( $ membership_process ['renew ' ] ) && in_array ( $ data ['current_membership_id ' ], $ membership_process ['renew ' ], true );
257257
258- $ currency = get_option ( 'user_registration_payment_currency ' , 'USD ' );
259- $ local_currency = isset ( $ response_data ['switched_currency ' ] ) ? $ response_data ['switched_currency ' ] : '' ;
260- $ ur_zone_id = isset ( $ response_data ['urm_zone_id ' ] ) ? $ response_data ['urm_zone_id ' ] : '' ;
258+ $ base_membership_amount = $ membership_amount ;
259+
260+ $ currency = get_option ( 'user_registration_payment_currency ' , 'USD ' );
261+ $ local_currency = isset ( $ response_data ['switched_currency ' ] ) ? $ response_data ['switched_currency ' ] : '' ;
262+ $ ur_zone_id = isset ( $ response_data ['urm_zone_id ' ] ) ? $ response_data ['urm_zone_id ' ] : '' ;
263+ $ pricing_data = null ;
264+ $ local_currency_data = array ();
265+ $ local_currency_applies = false ;
261266
262267 if ( ! empty ( $ local_currency ) && ! empty ( $ ur_zone_id ) && ur_check_module_activation ( 'local-currency ' ) ) {
263268 $ pricing_data = CoreFunctions::ur_get_pricing_zone_by_id ( $ ur_zone_id );
264269 $ local_currency_data = ! empty ( $ data ['local_currency ' ] ) ? $ data ['local_currency ' ] : array ();
265270
266271 if ( ! empty ( $ local_currency_data ) && ur_string_to_bool ( $ local_currency_data ['is_enable ' ] ) ) {
267- $ currency = $ local_currency ;
268- $ membership_amount = CoreFunctions::ur_get_amount_after_conversion (
272+ $ currency = $ local_currency ;
273+ $ local_currency_applies = true ;
274+ $ membership_amount = CoreFunctions::ur_get_amount_after_conversion (
269275 $ membership_amount ,
270276 $ currency ,
271277 $ pricing_data ,
@@ -281,7 +287,11 @@ private function prepare_paypal_context( $data, $membership, $member_email, $sub
281287 $ discount_value = 0.0 ;
282288
283289 if ( $ is_upgrading ) {
284- $ final_amount = (float ) ( isset ( $ data ['amount ' ] ) ? $ data ['amount ' ] : $ final_amount );
290+ // $data['amount'] is the prorated delta in the base currency — scale it by the plan's local/base ratio.
291+ $ chargeable_amount_base = (float ) ( isset ( $ data ['amount ' ] ) ? $ data ['amount ' ] : $ final_amount );
292+ $ final_amount = ( $ local_currency_applies && $ base_membership_amount > 0 )
293+ ? $ membership_amount * ( $ chargeable_amount_base / $ base_membership_amount )
294+ : $ chargeable_amount_base ;
285295 } elseif ( ! empty ( $ data ['coupon ' ] ) && ur_check_module_activation ( 'coupon ' ) ) {
286296 $ coupon_service = new CouponService ();
287297 $ coupon_validation = $ coupon_service ->validate (
@@ -292,11 +302,26 @@ private function prepare_paypal_context( $data, $membership, $member_email, $sub
292302 );
293303
294304 if ( $ coupon_validation ['status ' ] ) {
295- $ coupon_details = ur_get_coupon_details ( $ data ['coupon ' ] );
296- $ discount_value = ( 'fixed ' === ( isset ( $ coupon_details ['coupon_discount_type ' ] ) ? $ coupon_details ['coupon_discount_type ' ] : '' ) )
305+ $ coupon_details = ur_get_coupon_details ( $ data ['coupon ' ] );
306+ $ coupon_discount_type = isset ( $ coupon_details ['coupon_discount_type ' ] ) ? $ coupon_details ['coupon_discount_type ' ] : '' ;
307+ $ discount_value = ( 'fixed ' === $ coupon_discount_type )
297308 ? (float ) ( isset ( $ coupon_details ['coupon_discount ' ] ) ? $ coupon_details ['coupon_discount ' ] : 0 )
298309 : ( $ final_amount * (float ) ( isset ( $ coupon_details ['coupon_discount ' ] ) ? $ coupon_details ['coupon_discount ' ] : 0 ) / 100 );
299310
311+ // Fixed discounts are configured in the base currency — convert before subtracting.
312+ if ( $ local_currency_applies && 'fixed ' === $ coupon_discount_type ) {
313+ $ discounted_base = max ( 0.0 , $ base_membership_amount - $ discount_value );
314+ $ discounted_local = CoreFunctions::ur_get_amount_after_conversion (
315+ $ discounted_base ,
316+ $ currency ,
317+ $ pricing_data ,
318+ $ local_currency_data ,
319+ $ ur_zone_id ,
320+ $ base_membership_amount
321+ );
322+ $ discount_value = max ( 0.0 , $ final_amount - $ discounted_local );
323+ }
324+
300325 $ final_amount = max ( 0.0 , (float ) user_registration_sanitize_amount ( $ final_amount - $ discount_value ) );
301326 }
302327 }
0 commit comments