Purchase Emerald subscription through Hikashop (recurring)

  • Posts: 38
  • Thank you received: 2
8 years 1 month ago #253694

-- HikaShop version -- : 3.0.0
-- Joomla version -- : 3.6
-- PHP version -- : 5.6
-- Browser(s) name and version -- : Chrome

Hello Nikolas.

This is Sergey Emerald developers. i have a question. You know that there is an integration that allows user to purchase emerald subscription though Hikashop. Some people asked me if user can let user purchase recurring subscriptions.

My question is.

1. Does your PayPal plugin support recurring payments?
2. If yes, how do I process subscr_payment or recurring_payment IPNs? In what event and if even is the same, how do I detect it is not a regular payment but rather a new charge?

Please Log in or Create an account to join the conversation.

  • Posts: 83023
  • Thank you received: 13403
  • MODERATOR
8 years 1 month ago #253709

Hi,

1. We've developed a specific plugin for PayPal reccurring:
www.hikashop.com/support/documentation/1...a-subscriptions.html
The akeeba subscription plugin also contains some specific triggers from the PayPal reccurring plugin so that both are compatible together. The goal was to make the PayPal reccurring plugin completely solution agnostic so that you could use it with any subscription extension by just implementing the triggers in the integration plugin.
2. In the PayPal recurring plugin, you can check see that HikaShop simply create a new order when a reccurring notification arrives. And that is picked up by the akeeba subscription plugin which extends the subscription period automatically.

So you'll have to focus on implementing some code in your HikaShop integration plugin based on the code from the akeeba subscription plugin:

function onCheckSubscription(&$subLevel,&$result){
		$db	= JFactory::getDBO();
		$query = 'SELECT * FROM '.hikashop_table('akeebasubs_levels',false).' WHERE akeebasubs_level_id IN ('.implode(',',$subLevel).')';
		$db->setQuery($query);
		$result = $db->loadObjectList();
		return true;
	}

	function onCheckSubscriptionPlugin(&$name){
		$name = 'akeebasubs';
		return true;
	}
onCheckSubscriptionPlugin is to define the name of the plugin you used from the integration
onCheckSubscription is to provide the levels based on what you have in the product_subscription_id of the products in the order.
The format should follow what you have in the akeebasubs_levels table since the PayPal reccurring plugin bases itself on that to process the payment data to be sent to PayPal.

Please Log in or Create an account to join the conversation.

  • Posts: 38
  • Thank you received: 2
8 years 1 month ago #253778

I am sorry not clear.

1. What are subscription levels? Plans?
2. based on this hikashop_table('akeebasubs_levels',false). Does that means hikashop have a table dedicated to Akeebasub? how does that make solution subscription extension agnostic?
3. onCheckSubscription in Emerald will set completely different data structure to $result. How that is gonna work?
4. "n the PayPal recurring plugin, you can check see that HikaShop simply create a new order when a reccurring notification arrives." so I have to use onAfterOrderUpdate event? Why do I need onCheckSubscription and onCheckSubscriptionPlugin?

Please Log in or Create an account to join the conversation.

  • Posts: 83023
  • Thank you received: 13403
  • MODERATOR
8 years 1 month ago #253804

Hi,

1. Yes, they are plans.

2. No it's a table of akeeba subscriptions where the plans are stored.
If you look at the sql install script of akeeba subscriptions, you can see the structure of that table:
github.com/akeeba/akeebasubs/blob/develo...nd/sql/xml/mysql.xml
We just used the structure of that table for the data to take in but you can just replicate that structure in $results.

3. For example, you could have a function like that:

function onCheckSubscription(&$subLevel,&$result){
// $subLevel is an array of subscription ids that the merchant set in the product_subscription_id column of the products of the order to link HikaShop products to subscriptions
		$object = new stdClass();
		$object->akeebasubs_level_id = 'XXX'; // where XXX is the id of your level in emerald that you set in the product_subscription_id of the product in HikaShop
		$object->duration = 31; // the duration of the renewal period
		$object->price = '10'; // the amount of the recurring fee
		$object->recurring = '1'; // the fact that is it a recurring subscription
		$result = array($object);
		return true;
	}
That would make it so that if in your cart, you have a products linked to the subscription XXX (with the value XXX in its product_subscription_id), it will display PayPal recurring as a payment method on the checkout and not the other payment methods and the PayPal recurring plugin will automatically setup a recurring payment every 31 days with a price of 10.
So in that onCheckSubscription function, it's up to you to load the subscription data from emerald's database, and make it translate to the $result array with the format that will be used by the PayPal recurring payment plugin.

2. Yes, you need to use onAfterOrderUpdate to create/extends subscriptions when orders are confirmed. That's the same principle whether the subscription is a recurring one or not.
The onCheckSubscription and onCheckSubscriptionPlugin function allows you to give to the PayPal recurring plugin the information of the duration of the recurring and the amount you want the customers to pay each time and whether a product is attached to a recurring subscription or not (you might be selling both types of products/subscriptions on your website) so that our system can properly handle the payments.
Basically, you don't have to care about how the payment is done, confirmed, etc.
You just provide the recurring options coming from the emerald subscriptions attached to the products and HikaShop handles the rest and the subscription creation/extension works the same as when you don't support recurring payments.

Please Log in or Create an account to join the conversation.

  • Posts: 38
  • Thank you received: 2
8 years 1 month ago #253868

OK, now I am getting it.

But look Emerald does not affect price. I mean right now, user create product in Hikashop, give it a price and that is what user pay through hikashop. And this price is irrespective of Emerald price. that means that is Emerald plan cost $10 and product in Hikashop that grant this plan cost $20, then this is how much user pay.

Why? Because user may create for example plan sets. Product that sell few different plan at once and give it discounted price. So Hikashop price override Emerald's. And I think this how it should work.

So how i make sure that recurring continues on the price user set in Hikashop?

Please Log in or Create an account to join the conversation.

  • Posts: 83023
  • Thank you received: 13403
  • MODERATOR
8 years 1 month ago #253897

Hi,

If you look at the settings of the PayPal recurring plugin, you can see that the first option on the right is "price from" which allows the merchant to choose whether PayPal recurring should use the price coming from the product in HikaShop or the price coming from the subscription in Emerald.
That's why you can specify the price of the subscription in the trigger.
I agreed that normally you want to use the price set in HikaShop.
But some merchants has some valid reasons to use the price in the subscription in Akeeba Subscriptions, so we made it an option so that the merchant can choose himself what to do based on his needs.

Please Log in or Create an account to join the conversation.

  • Posts: 38
  • Thank you received: 2
8 years 1 month ago #254022

OK. This means that onCheckSubscription and onCheckSubscriptionPlugin methods exists only to get the price. I am sorry that I cannot get it so simple. How does onCheckSubscription nows about $level? I mean how does it know about pland_id? For example in Emerald I integrate it so that Hikashop has no clue what plan_id is bound to this particular product. In order to return $result object with price, I need ID of Hikashop product rather than pland_id. And by that product I can determine what plan is bound to that.

Another question, if my integration use only Hikashop price, do I need to create onCheckSubscription and onCheckSubscriptionPlugin at all?

Please Log in or Create an account to join the conversation.

  • Posts: 83023
  • Thank you received: 13403
  • MODERATOR
8 years 1 month ago #254026

Hi,

Normally, you're supposed to stored the plan_id in the product_subscription_id column of the product in order to linked the products and the plans in your extension.
So $subLevel returns an array of all the product_subscription_id of the products in the order.
The product information is not available in the onCheckSubscription trigger.
You would have to implement also the onAfterCartProductsLoad trigger in order to store the list of the products in this like that:
$this->products =& $cart->products;
so that you could then use $this->products in onCheckSubscription.
Even if you only use the HikaShop price, you still need to implement the onCheckSubscription and onCheckSubscription triggers.
The only difference is that you would have to set the price of the product in $object->price instead of using the one from your subscription so that regardless of how the "from price" setting is configured in the PayPal recurring plugin, it would always use the product price.

Please Log in or Create an account to join the conversation.

  • Posts: 38
  • Thank you received: 2
8 years 1 month ago #254734

Here is where the problem. You see my integration style is done the way, that Hikashop knows nothing about Emerald and if this or that product connected to any Subscription plan or not. So Hikashop is subscription extension Agnostic. And I think this is the best way. As soon as you implement some interface for subscription extensions in Hickshop there are lot of problems. Like this one now. One extension works one way and other extension work the other way.

So what is the solution in this case?

For me, if you just trigger onAfterOrderUpdate, would be enough for me to update subscription if needed.

I do not know how I can pass the price to onCheckSubscription and I do not want, Emerald affect price of the product. Can you allow users to sett recurring payment rules even without this methods? Then everything have to work.

Please Log in or Create an account to join the conversation.

  • Posts: 83023
  • Thank you received: 13403
  • MODERATOR
8 years 1 month ago #254813

Hi,

I was just suggesting the easiest solution for you. But you can do it the way you want really. You can even have your own PayPal recurring plugin integrated with HikaShop and Emerald.
The only requirement is to implement both functions onCheckSubscription(&$subLevel,&$result) and onCheckSubscriptionPlugin(&$name) in your Emerald / HikaShop integration plugin and in $result you need to set an array of objects with recurring set to 1 of you want recurring payments. That's necessary so that HikaShop can discard other payment plugins that don't support recurring payments during the checkout if the order contains products that do necessite recurring payments.
And as I explained in my previous message, you can get the list of the products by implementing the trigger onAfterCartProductsLoad.

And the price doesn't have to be given if you don't want to. Just don't. If the merchant uses our PayPal recurring plugin and that you make your integration compatible with it, it would mean that the customer would always get the product price.
And if you do your own PayPal recurring plugin, you can handle it any way you want.

And regardless what you choose, onAfterOrderUpdate or onAfterOrderCreate will be called all the time when an order is created or confirmed, so you can add/update your subscriptions the way you want.

Please Log in or Create an account to join the conversation.

Time to create page: 0.070 seconds
Powered by Kunena Forum