• Resolved kristarella

    (@kristarella)


    Is it possible to modify the checkout amount using PHP?

    I want to do this in order to pro-rate payments for members when they upgrade. I believe I have figured out how to calculate the needed amount, but I don’t know where I can hook in to the checkout form to apply the deduction.

    https://ww.wp.xz.cn/plugins/s2member/

Viewing 12 replies - 1 through 12 (of 12 total)
  • cassel

    (@cassel)

    You just want to change the price for future customers or the payment for current customers who might have a recurring payment plan?

    If it is just to change the price for the future customers, simply edit the amount in the button code, whether it is a shortcode or a php code.

    To change a price for a payment plan, I think you have to go to Subscription modification.

    Thread Starter kristarella

    (@kristarella)

    It is for current members/subscribers wishing to upgrade their subscription level. We are using the modify form to handle the change in membership level and that works fine. I just need to be able to apply a discount according to how much the member has already paid and how far through that payment period they are.

    So, it’s not a matter of changing the shortcode since the amount is going to be different for each member. The modification form has the same prices as the registration form, it’s a matter of applying the appropriate discount for each member when they apgrade.

    In that case you’d have to first figure out how much paid time they have left, and either add it as the initial term of the new subscription, or calculate how much it is in money and discount it from the first payment as the initial term.

    You’d use the initial term, free or paid, because it can be different from the regular terms, which will all be the same. Does that help?

    You do those things in PHP and apply them to the shortcode attributes when you display the form. http://www.s2member.com/kb/using-variables-in-a-shortcode/

    “Is it suitable to use pro support for how-to Qs?”

    Maybe, I’m not sure I understand exactly what you mean. Do you need to control access to those how-to Qs? If so, yes.

    Thread Starter kristarella

    (@kristarella)

    Thanks for getting back to me!

    You do those things in PHP and apply them to the shortcode attributes when you display the form.

    How would I use the shortcode variable in this case? Perform a redirect to include the query string when any logged in user hits that page? I guess that could work.

    “Is it suitable to use pro support for how-to Qs?”

    Maybe, I’m not sure I understand exactly what you mean. Do you need to control access to those how-to Qs? If so, yes.

    Obviously Twitter is too brief for such a question. I meant is it suitable to use the s2member pro support to ask questions on how to do things in s2member Pro, now that the s2 forums are closed? I have started to use the email support a couple of times, but the process always discourages me from trying to ask anything that isn’t about a bug report.

    Here are a couple of examples:
    http://www.primothemes.com/forums/viewtopic.php?f=36&t=15889&p=53557#p53418
    http://www.s2member.com/forums/topic/recurring-prorating-of-billing/#post-7410

    I hope that helps. 🙂

    Sure, you can send me questions through the helpdesk too, not just bug reports. Thanks for the feedback on the form, I’ll talk with Jason to see how we can improve it.

    Thread Starter kristarella

    (@kristarella)

    Thanks for all your help. I think I am nearly there, I can add the variable etc, but I am having trouble finding the EOT/renewal date and last paid amount for the calculation.

    Since they are Payflow recurring subscriptions they have no EOT set in the user data, so I guess I need to get the PayPal subscription data to get the next payment date, but I’m having trouble with that. If I use

    $paypal = array ("METHOD" => "GetRecurringPaymentsProfileDetails", "PROFILEID" => $user['sub_ID']);
    print_r(c_ws_plugin__s2member_paypal_utilities::paypal_payflow_api_response ($paypal));

    I get Array ( [RESULT] => 2 [PNREF] => VR00******** [RESPMSG] => Invalid tender [__error] => Error #2. Invalid tender. )
    and if I use

    $paypal = array ("METHOD" => "GetRecurringPaymentsProfileDetails", "PROFILEID" => $user['sub_ID']);
    print_r(c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal));

    I get
    Array ( [TIMESTAMP] => 2014-05-15T07:28:06Z [CORRELATIONID] => 37f6bf4c87d44 [ACK] => Failure [VERSION] => 71.0 [BUILD] => 10958405 [L_ERRORCODE0] => 10002 [L_SHORTMESSAGE0] => Security error [L_LONGMESSAGE0] => Security header is not valid [L_SEVERITYCODE0] => Error [__error] => Error #10002. Security error. Security header is not valid. )

    I can see in my Payflow logs that there’s a NEXTPAYMENT response in the API response, I’m just not sure how to fetch that for a particular user in my script.

    I’m basing that code for contacting the API on http://www.s2member.com/forums/topic/last-payment-time-is-wrong/#post-28491

    > Since they are Payflow recurring subscriptions

    Could you confirm that you’re using PayPal Pro PayFlow Edition and not PayFlow Pro? http://www.s2member.com/kb/paypal-pro-payflow-dprp-express-checkout/

    Did you ask PayPal about that error when you doing the query?

    I’ll ask Jason in case he knows what’s going on there. 🙂

    Here’s what Jason said:

    “They are mixing the API args for PayPal Pro with the class method that interacts with the PayPal Pro (Payflow Edition) call. There is actually another wrapper for Payflow that is a bit easier to work with.”


    $subscr_id = get_user_option('s2member_subscr_id', $user_id);
    $payflow_profile = c_ws_plugin__s2member_pro_paypal_utilities::payflow_get_profile($subscr_id);
    // print_r($payflow_profile); // This is an array of details about the recurring profile.

    Thread Starter kristarella

    (@kristarella)

    Thank you! This thread has been hugely helpful.

    FYI for anyone else who might benefit. The above payflow_get_profile method gave me everything I needed except the last payment amount to calculate the appropriate prorated amount. I found it with a combo of the payflow_get_profile method and a parameter I found in the Payflow recurring billing guide:

    $payflow["TRXTYPE"] = "R";
    $payflow["ACTION"] = "I";
    $payflow["TENDER"] = "C";
    $payflow["PAYMENTHISTORY"] = "O";
    $payflow["ORIGPROFILEID"] = $subscr_id;
    
    if(($profile = c_ws_plugin__s2member_paypal_utilities::paypal_payflow_api_response($payflow)) && empty($profile["__error"]))
    	print_r($profile);

    Returns all the payments in the profile.

    Fantastic! Thanks for sharing that. I’m very glad you got it working. 🙂

    Thread Starter kristarella

    (@kristarella)

    If I could get some more help on this I would greatly appreciate it. I got all the calculations sorted out and pass the appropriate discount amount to the form via query in the URL, which is then added to the checkout form as a hidden field:
    <input type="hidden" id="s2-custom-pro-rate-amt" name="s2_custom_pro_rate_amt" value="<?php echo $_GET["amt"]; ?>" />

    My function to subtract the discount from the total was not working. Although I just spotted an error so maybe it is working now… I have never had much luck getting the PayPal sandboxes working, particularly with Payflow, which we’re using on the site in question. Can you suggest a suitable way to test this code? I tried just viewing the results of the form submission, but most of it was encrypted.

    If you want to test it directly you could just change $disc = bd_pro_rate_amount(); to $disc = 20; or some other fixed amount. I am using the same function that produces the discount amount for the query string so that no wise guys cotton on to the discount in the URL and game the system.

    add_filter("ws_plugin__s2member_pro_paypal_checkout_post_attr", "bd_paypal_pro_checkout_form_attr");
    function bd_paypal_pro_checkout_form_attr($attr = array()) {
    	if (isset($_POST["s2_custom_pro_rate_amt"])) {
    		$disc = bd_pro_rate_amount();
    		if($_POST["s2_custom_pro_rate_amt"] > 0 && isset($attr["ta"])) {
    			if ($attr["ta"] > $disc)
    				$attr["ta"] = $attr["ta"] - $disc;
    			else
    				$attr["ta"] = 0;
    		}
    		elseif($_POST["s2_custom_pro_rate_amt"] > 0 && !isset($attr["ta"])) {
    			if ($attr["ra"] > $disc)
    				$attr["ta"] = $attr["ra"] - $disc;
    			else
    				$attr["ta"] = 0;
    
    			$attr["tt"] = "Y";
    			$attr["tp"] = 1;
    		}
    	}
    	return (array) $attr;
    }
Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Modify Checkout Amount’ is closed to new replies.