maleli VIP
Total posts: 87
17 Июнь 2014 22:32

Hi, I'm creating a Payment Gateway to Work with ClickBank. I almost have it working (I think).

In ClickBank I set up each product, pretty much like I do in Emerald. They just require a button to their payment gateway, which I was able to easily build with the oayment gateway in emerald. The link looks like this:

http://ITEM.VENDOR.pay.clickbank.net

So I just set up item and vendor in the Emerald parameters and the price info and everything else is stored in ClickBank.

Then, in ClickBank I need to define a thank you URL, which I am guessing is what would activate the subscription. So I defined it like this:

http://mysite.com/component/emerald/?task=payment.back

All the parameters that emerald gathers are also sent to ClickBank and then back to Emerald.

ClickBank handles payment (through paypal or other) and after payment is confirmed by ClickBank the subscriber gets a link that says "click here to access your digital product" with the following link:

https://ssl.clickbank.net/order/lo gCompletion.html;jsessionid=00000.NO4?receipt=00000&redirect=http%3a%2f%2fmywebsite.com%2fcomponent%2femerald%2f%3ftask%3dpayment.back%26item%3d1001-vac%26cbreceipt%00000%26time%00000%26cbpop%3d00000%26cbaffi%3d0%26cname%3dNombre%2bapellido%26cemail%3dapps%2540iniciativat.com%26ccountry%3dGT%26czip%3d%26notify_url%3dhttp%253A%252F%252Fmywebsite.com%252Fcomponent%252Femerald%252F%253Ftask%253Dplans.create%26Itemid%3d1%26processor%3dpaypal2%26em_id%3d48%26vendor%3dCambio360%26cb_item%3d1001-VAC%26return%3dhttp%253A%252F%252Fmywebsite.com%252Fcomponent%252Femerald%252F%253Ftask%253Dpayment.back%26Itemid%3d1%26processor%3dclickbank%26em_id%3d48%26cancel_return%3dhttp%253A%252F%252Fcursosiniciativat.com%252Fcomponent%252Femerald%252F%253Ftask%253Dpayment.back%26Itemid%3d1%26processor%3dclickbank%26em_id%3d48%26lc%3dEN%26rm%3d2%26cmd%3d_xclick%26email%3dmyemail%2540mywebsite.com%26amount%3d35%26charset%3dutf-8%26item_name%3dCurso%2bPrueba%2b%255BCBCursos%255D%26no_shipping%3d1%26currency_code%3dUSD%26tax%3d0.00&redirectsum=08343387E30AB6B&button=LINK_TOP

And the subscriber is taken to the following page: http://mysite.com/mis-suscripciones.html?view=emhistory

Where they get a message saying that the subscription has not yet been activated. Is there any other parameter that I'm missing that needs to be sent back from ClickBank so the subscription can be automatically activated?

Thank you!

Последние изменения: 26 Июнь 2014


Sergey
Total posts: 13,748
18 Июнь 2014 00:53

Еруку have to be URL to communicate with Emerald. Notification URL. The URL where CB will send request with success purchase confirmation.

This URL is for returnig back

 http://mysite.com/component/emerald/?task=payment.back 

But this URL if for accepting requests to process activation in the same plugin.

 http://mysite.com/component/emerald/?task=plans.create& ;processor=clickbank

Then in your plugin you have to have get_subscrption_id function which return ID of the subscription. But that is imposible. Because ClickBank does not have it. This means that with each order, somehow you have to path $subscription->id so you can reseive it later and understand what is subscription we have to process.

I read this

https://support.clickbank.com/entries/22803622-Instant-Notification-Service

SO one of ther returning parameters should be subscription ID not plan ID. Because you have to know what subscription to activate in accept method of the plugin.

You only need to set $subscription->published = 1 and $subscription->gateway_id = $_POST['ctransreceipt'].

What I would do I would test it like this. I would redirect user to

 http://ITEM.VENDOR.pay.clickbank.net?subscription_id= $subscription->id

And I would check if this is returned in the pareamters.

Anyway the only way to eneable automatic activation is to be able on return or notification URL detect what is ID of the subscription we have to process.


maleli VIP
Total posts: 87
18 Июнь 2014 19:01

Thank you!

I just tried this and the subscription was sent to ClickBank and back, but I get an error.

I get this return url: http://mysite.com/component/emerald/?task=plans.create& ;processor=clickbank&item=1001-vac&cbreceipt=XMFLEKYR&time=1403117583&cbpop=6EBA1D0B&cbaffi=ABC&cname=m+h&cemail=subscriber%mysite.com&ccountry=GT&czip=01015&subscription_id=48notify_url%3Dhttp%3A%2F%2Fmysite.com%2Fcomponent%2Femerald%2F%3Ftask%3Dplans.create&Itemid=1&processor=clickbank&em_id=48&vendor=cambio360&cb_item=1001-VAC&return=http%3A%2F%2Fmysite.com%2Fcomponent%2Femerald%2F%3Ftask%3Dpayment.back&Itemid=1&processor=clickbank&em_id=48&cancel_return=http%3A%2F%2Fmysite.com%2Fcomponent%2Femerald%2F%3Ftask%3Dpayment.back&Itemid=1&processor=clickbank&em_id=48&lc=ES&rm=2&cmd=_xclick&email=vendor%mysite.com&amount=35&charset=utf-8&item_name=Curso+Prueba+[CBCursos]&currency_code=USD

I get this message:

500 - Imposible verificar transacción


Sergey
Total posts: 13,748
20 Июнь 2014 03:07

What is in your accept function of plugin?

Actualy as I said, it will not go thorugh because Emerald does not know what subscription to load because there is no subscription ID in response.

But I see subscription_id=48 in URL. Where is it from? And why no & after? Is is ID of the plan or id of subscription? If second you need function in gateway

function get_subscrption_id($who)
{
   return JFactory::getApplication()->input->get('subscription_id');
}

maleli VIP
Total posts: 87
20 Июнь 2014 16:30

Thanks, I did it just like you said.

I added this:

http://ITEM.VENDOR.pay.clickbank.net?subscription_id=$subscription->id

And it did retrieve a valid subscription id. It seems like Emerald did know what subscription to load when it sends parameters to ClickBank because the subscription 48 was correct, it was the one I was testing with.


Sergey
Total posts: 13,748
23 Июнь 2014 06:22

To me it all have to be like this.

<?php
jimport('joomla.application.menu');

class EmeraldGatewayClickBank extends EmeraldGateway
{
    function accept(&$subscription, $plan)
    {
        $this->log('Start check ClickBank');

        $subscription->published = 1;
        $subscription->gateway_id = $this->get_gateway_id();

        EmeraldHelper::activateSubscription($subscription, $plan);
        $subscription->store();

        EmeraldHelper::redirect($plan, $subscription->published);

        return TRUE;
    }


    function pay($amount, $name, $subscription, $plan)
    {
        $url = 'http://' . $this->params->get('cb_item') . '.' . $this->params->get('vendor') .
            '.pay.clickbank.net?subscription_id=' . $subscription->id;

        JFactory::getApplication()->redirect($url);

    }


    function get_gateway_id()
    {
        return (int)JFactory::getApplication()->input->get('ctransreceipt');
    }

    function get_subscrption_id($who)
    {
        return (int)JFactory::getApplication()->input->get('subscription_id');
    }
}

maleli VIP
Total posts: 87
24 Июнь 2014 19:35

Thanks! Works great! :)


maleli VIP
Total posts: 87
25 Июнь 2014 01:17

One more detail, sorry.

In the confirmation email, no order number is sent.

Click Bank sends back a 'receipt' URL variable. If I grab it's value, how can I convert that to order number in Emerald so that it's sent in the confirmation email?

Based on the paypal gateway I added this:

function get_plan_id()

    {

        return JFactory::getApplication()->input->get('receipt');

    }

Thanks


Sergey
Total posts: 13,748
25 Июнь 2014 02:12

I think you have to change this

function get_gateway_id()
{
    return JFactory::getApplication()->input->get('ctransreceipt', JFactory::getApplication()->input->get('receipt'));
}

because get_plan_id is not involved in the process. This method exists only for Mighty membership transfer old IPNs support. It is never called in your plugin.


maleli VIP
Total posts: 87
25 Июнь 2014 18:27

Thanks! It works. In case this is helpful to someone else, it works with 'cbreceipt'. Thanks!


Sergey
Total posts: 13,748
25 Июнь 2014 23:40

Would be nice if you share clickbank plugin in depot :)


maleli VIP
Total posts: 87
26 Июнь 2014 00:54

Sure, don't know how bulletproof it is but it seems to be working fine, so I'll share it. Thanks for your help.

Работает на Cobalt