Custom Payment Gateway for Membership

I am working on a custom payment gateway using Eway Shared Payments API for Membership Plugin.

I have an issue with handling the response back from the payment gateway after the payment is done.

As described in many posts on wpmu, I started with taking gateway.paypalexpress.php file as a reference to create my custom payment gateway for Eway.

I wrote a simple static code that sends a request URL to eway, gets a token id using CURL & then redirects user to the payment gateway page for payment.

The payment is done successfully but when it returns back with a response, the response is not fetched.

I had added the response-handling code in handle_eway_return() [handle_paypal_return()] method on "membership_handle_payment_return_" hook.

But that didn't work.

So i even tried adding the response-handling code in the class' constructor.

But it shows just a blank white screen on returning. [WP_DEBUG is set to true]

However when I am using Eway Shared API's sample code file that handles response I was able to fetch the response after payment is done & redirection occurs from gateway's page to website.

I just had to set its path as value in ReturnUrl parameter when request is made.

I have attached the custom payment gateway file with this post.

Thanks in adv.

  • wisdmlabs

    Hi Ari,

    I am sorry I complicated this question a bit.

    Let me simplify this question.

    I just want to know how to handle the response I get from my payment gateway (Eway Shared Payments).

    My method handle_eway_return() on action hook 'membership_handle_payment_return_' doesn't seem to work.

    My Payment Request works fine & redirects to the payment gateway site but after payment is done it redirects as per the return URL.

    I just want to make handle_eway_response() method run. I think the issue is with the
    'membership_handle_payment_return_' hook. Can u explain how it works.

    May be that could help me solve this problem.


  • Hoang Ngo

    Hi @wisdmlabs,

    I hope you are well today and I'm sorry about the delay.

    The way membership handler the payment return, mostly by IPN concept. The flow of it will be
    1. You will need to define the IPN url return on your payment gateway, and it should be http://yourdomain/paymentreturn/yourgatewayname
    For more information, you can check the function add_rewrites in file plugins/membership/membershipincludes/classes/membershippublic.php
    2. At same file, you will see the function handle_paymentgateways, called by the hook pre_get_posts, this is where the plugin called function to process the payment return.

    If your payment return not work, so you will need to check does the IPN return is valid, if your gateway don't support IPN, or it will redirect user to your site with transaction params, so you will need to add an action like add_action('pre_get_posts','your function'), and your function will need to check does the return is valid and process the payment.

    Hope that information will help :slight_smile:

    Best Regards

  • wisdmlabs

    Hi Hoang,

    Thanks for your inputs.

    This solved my problem & now redirection happens properly after the payment is done.

    I have few more questions:

    1) Can I dynamically change the price of a subscription when a person is renewing the membership?

    A client needs a functionality where she could charge $20 if an existing member doesn't renew on time.

    Which hook will help me achieve this?

    2) Can membership support a Pro-Rated payments along with standard annual payments?

    For E.g The annual payment for a particular subscription is charged $100 from June to June. But if a person joins from September he must be charged less, say like $ 75.

    To summarize, I just want a way to reduce the price of membership as duration of the membership decreases.

    I know it will have some custom coding but if you could guide me a little , it would be of great help.

    Thanks in Advance.

    Best Regards,

  • Hoang Ngo

    Hi @wisdmlabs,

    1. Hmm, usually we do the renew for client automatic by recurring and client confirm that, otherwise, there's no way to charge client. I think you can add the penalty fee when client review at the next time. So the situation like this,
    the amount is 20$ a month, client has late on the renew, so later, when he go to the renew form, the price will he 40$.

    2. As Vaughan said, it's current not support for now :slight_frown:. But how about the coupon system, you can create coupon with value, and then filter to the apply price function by this filter "membership_coupon_price", return new price base on the current user data.
    Example how to use the filter

    function new_price($new_price, $price, $coupon){
    //your logic here

    Best Regards,

  • wisdmlabs

    Hi Hoang,

    I used the 'membership_coupon_price' filter & it works fine for updating the price after the coupon is entered.

    However I want to discuss two things with you:

    1)The filter 'membership_coupon_price' works when I click on 'Apply coupon' button.

    Is there any 'hook' that can help me call this filter before the page that renders 'subscribe' button gets loaded? [So that I can automate this process & the user doesn't have to click on 'Apply_Coupon']

    In that filter I can have my Pro-Rata Logic & it will eventually fulfill my requirememnt.

    2) I found out that when I activate BuddyPress & Xprofile , and when I enter any existing coupon code it shows 'Coupon Code is invalid'.

    But when I deactivate both BuddyPress & Xprofile, the same coupons work absolutely fine.

    Thanks in Advance.

    Best Regards,

  • Hoang Ngo

    Hi @wisdmlabs,

    1. The process coupon code get call when the hook "template_redirect" processed.

    At the file membership/membershipincludes/classes/membershippublic.php you will find this function

    // coupon processing
    					$coupon = filter_input( INPUT_POST, 'coupon_code' );
    					$sub_id = filter_input( INPUT_POST, 'coupon_sub_id', FILTER_VALIDATE_INT );
    					if ( $logged_in && $coupon && $sub_id ) {
    						$coupon = new M_Coupon( $coupon );
    						$coupon_obj = $coupon->get_coupon();
    						if ( $coupon->valid_coupon() && $coupon_obj->discount >= 100 && $coupon_obj->discount_type == 'pct' ) {
    							$to_sub_id = $sub_id;

    This is how it handler the coupon, through POST, so you can follow this and do something similar.
    2. Hmm, I have do some test but I can not reproduce the bug, do you have any cache plugin installed ?

    Best Regards,

  • wisdmlabs

    Hi Hoang,

    Thanks for your inputs.
    The coupon logic worked for me to do pro-rata.
    Also i used a hook o automate this process.

    However could you please explain me how do you get variable 'txn_type' for custom payment gateways?
    I checked the code and found out that just PayPal gateway has this parameter.

    I need this parameter so as to distinguish different transactions : subr_signup, updarde,renew etc.

    For now, I have manually set this parameter in the code which is sent to payment gateway & then retrieved in handle_eway_return() method [ my method that executes after redirection occurs from Eway Payment Gateway]


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.