Jump to content

Non-Merchant Gateway - Capturing Payments / Automatic Billing


sktan

Recommended Posts

Hi,

 

At the moment I'm working on a non-merchant payment-gateway for paypal / stripe which uses tokens / references in order to charge pre-authorised payments out of the client's account.

An issue I've come across is that the current Blesta non-merchant payment gateways dont seem to seem to support the 'capture' method which I assume should be called when new invoices are processed so we can use the payment references / tokens in order to process new payments.

 

Currently I see that I may need to modify the blesta/components/gateway_payments/gateway_payments.php and most probably some controller/model/other files in order to add the funcionability to be able to use pre-authorised payments.

Is there a way I can get around this? (The event hooks documentation doesn't show much information)

 

Thanks,

Link to comment
Share on other sites

I not yet worked on Blesta gateway,

 

But I do not understand were you have issue.

 

If you want to use "capture" transaction status returned by your gateway for pass invoice as paid, using condition that check returned transaction status and in case of "capture" status returned by gateway, you makes it use the matching Blesta function for a success/paid transaction, and that's it?

 

 

other, If before "capture" you are using "pre-authorization" status,  when blesta receive this transaction status, should update invoice/order to a new status from it's origin status like "pending" or "on hold" but never to "paid" status, because it's just not really paid.

Link to comment
Share on other sites

I not yet worked on Blesta gateway,

 

But I do not understand were you have issue.

 

If you want to use "capture" transaction status returned by your gateway for pass invoice as paid, using condition that check returned transaction status and in case of "capture" status returned by gateway, you makes it use the matching Blesta function for a success/paid transaction, and that's it?

 

 

other, If before "capture" you are using "pre-authorization" status,  when blesta receive this transaction status, should update invoice/order to a new status from it's origin status like "pending" or "on hold" but never to "paid" status, because it's just not really paid.

 

My problem isn't the understanding of what the capturing does.

It's the method of implementing the tokens and recurring payments that's is where I'm stuck as non-merchant gateway methods don't seem to be designed for that.

And modifying the UI of merchant-gateways has lead me nowhere as I can't figure out which controller handles the input of the CC details after the order form.

 

E.g. for Paypal, we get returned to the Success URL with a token in as a GET parameter but I haven't found a way to access the GET parameter in order to use the token for the next step of the tokenized payment process.

https://developer.paypal.com/docs/classic/express-checkout/ht_ec-refTrans-SetEC-DoRefTrans-curl-etc/

 

Also if I were to program the StripeJS gateway, I'd have to edit the views for the various credit card inputs which means editing core files as blesta does not currently support views within the gateways (from what I've read in the docs).

So in order to implement both gateways, I'm still looking for the simplest methods that allows for easy intergration whilst minimising the modification of the core blesta views / models / controllers.

Link to comment
Share on other sites

You said:

--------------------

the 'capture' method which I assume should be called when new invoices are processed so we can use the payment references / tokens in order to process new payments.

--------------

 

I think it's not that way it's work, you just have invoice/order created at blesta, and when customer paid it, your payment gateway send an notification to blesta, with the status of the transaction like : authorized, pending, success, etc....it's depend of each gateway.

 

and at blesta you use this returned status to update blesta order status (but first you must check that the notification is authentic and really from the gateway)

Link to comment
Share on other sites

You said:

--------------------

the 'capture' method which I assume should be called when new invoices are processed so we can use the payment references / tokens in order to process new payments.

--------------

 

I think it's not that way it's work, you just have invoice/order created at blesta, and when customer paid it, your payment gateway send an notification to blesta, with the status of the transaction like : authorized, pending, success, etc....it's depend of each gateway.

 

and at blesta you use this returned status to update blesta order status (but first you must check that the notification is authentic and really from the gateway)

 

Oh right, yes I see what you mean I was wrong in my assumption although that is somewhat unrelated to what I require.

 

Currently for non-merhant gateways, the process goes similar to this:

Order form -> Press Paypal Button -> Payment processes then notifies IPN -> Invoice Success!

 

What I want is

Order Form -> Press Paypal Button -> Buyer agrees to billing agreement -> returns to confim page -> Buyer confirms payment -> Gateway uses token in GET parameter to request payment -> Paypal confirms payment -> Invoice success!

 

Then for recurring payments:

Automatic Billing Cron -> Invoice Generated -> Paypal Gateway process payment -> Gateway sends another payment request using the token -> Invoice payment success!

 

Currently the only methods for automatic billing which are support are the merchant ones. I'd like to stay away from merchant gateways as I'd rather blesta not touch any of the credit card details what so ever.

 

I've noticed that blesta does maybe support this feature although the documentation is unclear as to if it's supported or unsupported.

http://docs.blesta.com/display/dev/Non-merchant+Gateway+Methods#Non-merchantGatewayMethods-buildAuthorize%28array$contact_info,$amount,array$invoice_amounts=null,array$options=null%29

 

It does say the capture method is un-supported, although there is no mention in the buildAuthorize page which would most-likely be perfect for my case.

Link to comment
Share on other sites

ok, sorry I can not real help, maybe an idea if you find it's can apply,

 

for your like IPN listener, try to see gateway returned variable value, using this php function, it's will check value from GET and POST

 

$field1 = $_REQUEST['field1'];

$field2 = $_REQUEST['field2'];

$field3 = $_REQUEST['field3'];

...

 

for test purpose. try to echo or if you cant not echo it, try auto-write these value in a test-table at database or auto-write received value in a file,

test before with a request from you, and next if got your field from your own request, try with the gateway

Link to comment
Share on other sites

ok, sorry I can not real help, maybe an idea if you find it's can apply,

 

for your like IPN listener, try to see gateway returned variable value, using this php function, it's will check value from GET and POST

 

$field1 = $_REQUEST['field1'];

$field2 = $_REQUEST['field2'];

$field3 = $_REQUEST['field3'];

...

 

for test purpose. try to echo or if you cant not echo it, try auto-write these value in a test-table at database or auto-write received value in a file,

test before with a request from you, and next if got your field from your own request, try with the gateway

 

I appreciate your help so far.

 

I've already logged the function calls, and I'm stuck attempting to find a way to request the paypal payment as after returning from paypal.

What' I've found is that the "success" method isn't invoked when the client lands back on the 'success' page as documentation implies, it is actually invoked as (I'm not too sure) the gateway gets notified of the payment being successful / unsuccessful (the IPN callback).

 

If anyone can help me with these queries, it would be also greatly appreciated:

Is it possible to redirect the client back to blesta (after their billing agreement) so that the NonMerchantGateway::getBuildAuthorize() method gets called in order for me to show the authorize page and then request their payment.

 

Is there a way for me to modify the view of the credit-card forms for merchant-gateways so StripeJS can be used?

Link to comment
Share on other sites

Hello sktan ..

i have laready worked in the paypal express  checkout gateway , but i have not finished it , but almost all of the work is done .

checkit here

http://pastebin.com/HELhSphK


it already was designed to support incontext payment , but as i have told before , no time was to finish it . if you can complete the worked we can build the incontext checkout also .

Link to comment
Share on other sites

in case that help, here bellow is generic explanation, I never worked with gateway for blesta.

 

--------------

 

 

about your question:

What' I've found is that the "success" method isn't invoked when the client lands back on the 'success' page as documentation implies, it is actually invoked as (I'm not too sure) the gateway gets notified of the payment being successful / unsuccessful (the IPN callback).

------------------

 

Because payment or update transaction status can be done later and not only just after an invoice/order was created, that the reason most payments gateway at 99% use:

 

- notification (POST OR GET or both at same time)

AND

- redirect/return

 

So for update order/invoice at the Billing system, you can not rely just on the redirect because when a customer will pay an invoice x day after it's was generated or when transaction status is updated, the customer could not be online or there is no redirection to manage b y the gateway(payment validated after x hours/day, etc), so all update you do at your billing system should be at based on Notification and not just based on the returned status in the redirection.

 

That why it's will be very logic Blesta method/function for update order/invoice status only rely on notification.

 

Returned status in the redirection just only serve you mostly to display the appropriate message to the customer, or if you update database from "redirection" why not, but you have also to do it from the notification (listener), and update will be done from first received, as there should be a status check done at database before to decide if current status is allowed to be updated.

 

update like :

- from "success" to "pending"

- from cancelled to success

- from success to "sucess"

 

should not be allowed

 

 

update from

pending or validated to success is allowed

 

 

update from

pending to validated

 

pending to cancelled

 

success to chargeback

 

are allowed

 

so for each case of returned status by the gateway there are order status check at database before to allow an update.

Link to comment
Share on other sites

That why it's will be very logic Blesta method/function for update order/invoice status only rely on notification.

 

Problem is not all gateways do notifications.

Some require polling the status of the transaction initiated after some time if the user wasn't redirected back.

Link to comment
Share on other sites

As it turns out my logging of the "success" function was kind of wrong.

It only gets called when paying for invoices via the dashboard, whereas if you're ordering a new product and get redirected from the payment gateway back to blesta, it's not being called as it should.

 

I'm still trying to find the most effective solution to capture / build a payment authorisation form afterr being redirected from the gateway.

I'd rather not create a hacky-implementation around the notify URL, although that seems as though it's the best option so far.

 

@naja7host

I appreciate you sharing your code in order to help me.

We both still fall into the same problem though when attempting to use pre-authorised billing agreements.

 

Update:

I've figured out a hacky-implementation of capturing payment tokens for future use.

Since the only method that seems available for us to use is "buildProcess", I've decided to use that in order to capture and authorize payments

public function buildProcess(array $contact_info, $amount, array $invoice_amounts=null, array $options=null) {
    // Builds our return_url based on the current page the client is on (also adds HTTP/s if supported)
    $this_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https://" : "http://";
    $this_url .= $_SERVER['HTTP_HOST'];
    $this_url .= $_SERVER['REQUEST_URI'];

    $options['return_url'] = $this_url;

    ......
}

This allows PayPal to return back to the buildPayment URL so we can then use the token passed back via a GET parameter in order to finalize our transaction.

Obviously not the best implementation that can be done, but it gets the job done.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...