- payments
- billing
- ecommerce
Accepting card payments on a website, a hosting company's experience
On paper a bank integration is a few lines, you send the customer to the bank's page and wait for the answer. In practice most of the time went on small details that are not written in the documentation. What we saw from the test environment to the first real payment.
A customer orders a server, enters their card, and two minutes later the server is ready. From the outside nothing looks simpler. We thought so too when we started.
In this post we describe how we connected card payments to the site, what went smoothly, what turned out differently from what we expected, and which decisions we still consider right. We do not name the bank, because most of what is written here does not depend on which bank you work with.
Card numbers are not stored with us
The first decision was the easiest. The customer types the card number not on our site but on the bank's own payment page. Our portal sends the customer to the bank's page, and once the payment is done the bank sends the customer back to a page on our portal.
This has two benefits. Card data never lands on our servers, so the most sensitive thing we would have to protect simply is not with us. Second, 3-D Secure confirmation (an SMS code or approval in the banking app) happens on the bank's own page, and the customer sees a screen they recognise.
From test to live in four days
On 12 October we ran the first complete payment in the test environment, 10 qapik. Two days later we ran the second test and sent the results to the bank. On 16 October we got access to the live environment and made the first real payment that same day, 1 manat confirmed with 3-D Secure.
So the technical part, once it is ready, does not take long.
What the documentation does not say
Most of our time went not on big issues but on small details.
The bank's test payment page is protected against automated access. We had written a script that ran test payments automatically, and the page rejected it every time. For a while we looked for the bug in our own code. The reason was simple, the page only lets through an ordinary browser operated by a person. So we ran the test payments by hand. This applies only to the testing stage, customers always pay in their own browser anyway.
The payment status names were written one way in the documentation's table and another way in the system's real responses. The difference was only upper and lower case, but for a program that is a completely different word.
The first test card in the documentation did not work in the test environment and returned "card not found". The second card worked. When you do not know this, you suspect your own code again.
None of these is a serious problem. But each one costs half a day, because you look for the mistake in your own work first.
The customer says "I paid". Is that true?
This was our most important decision. When the customer comes back from the bank's page, we do not trust the "success" flag that arrives in the address bar.
The reason is clear. That address passes through the customer's browser, which means it can be changed. So we ask the bank about the state of every payment separately, from our own server, and close the invoice only when the bank says "fully paid".
The second case happens more often. The customer pays and closes the browser without returning from the bank's page. The money has left, and we know nothing about it. For this there is a check that runs every minute and asks the bank itself about the state of pending payments. An order not paid within 24 hours is considered expired.
During the test period we took one more precaution, test mode was visible only to our own test account. Otherwise someone could have marked a real invoice "paid" with a test card.
The whole flow in one diagram looks like this.
Saving the card, built but not switched on yet
Hosting is a monthly service, so saving the card and charging it automatically every month is a natural wish. We built this feature according to the documentation and released it.
In a real test it did not work. The card was not saved, and the recurring payment request was rejected. A second attempt gave the same result. It turned out that this capability is not enabled automatically on every payment terminal, it has to be activated separately.
We switched the feature off and asked the bank to activate it. The answer was short, for newly connected partners this option is not turned on straight away, you first need to work with ordinary payments for a while.
One thing is worth knowing here. Some banks are cautious, even a little fussy, with a newly connected partner. Even when a feature is technically ready, they may not switch it on right away, may add conditions or may take their time deciding. This has nothing to do with your code, it is the bank's own policy, and it gets resolved with time.
While waiting, we also started talks with a second payment provider. Not depending on a single provider is at least as important as a technical backup.
There is a lesson on our side too. Not every capability described in the documentation is necessarily enabled in your contract. We should have asked before writing the code.
Refunds
Taking the money is half the job. Giving it back needs more care, because a mistake there is costly for both sides.
A payment made the same day is reversed, while on later days a refund is issued. For the bank these are different operations. If a reversal is rejected, our system switches to a refund by itself.
The trickiest part is a communication error. We sent a refund request and no answer came. Did the money go back or not? We do not know. In that case we record the result as "unknown" and block any retry. Otherwise there is a risk of refunding the same money twice.
We will admit one mistake too. In the first version, when a customer cancelled a service, the full amount went back to the card, even though part of the service had already been used. We fixed this in November, now only the amount left on the balance goes back to the card.
Ordering in the middle of the month
All services are billed to the 1st of the month, and the customer receives one combined invoice each month. A customer who orders on the 20th should not pay for a full month, though. So the first payment is calculated for the days left until the end of the month.
This is fair to the customer, but it has a side effect, the first payment is often one or two manat. Small amounts go through card payments without problems, you just need to show the customer clearly where that figure comes from.
Individuals pay by card. Companies can also pay by bank transfer, because most accounting works with invoices rather than card statements.
What we learned
Do not trust any answer that comes from the browser. The truth about a payment is in the bank's system, ask it there.
"Unknown" is an answer too. If you do not know the outcome of a money operation, do not guess and do not retry, stop and let a person look.
The documentation is the map, not the territory. A test card may not work, a status name may be spelled differently, a described feature may be switched off for you. Check each of them with a real test.
Do not depend on a single payment provider. When you are newly connected, some banks are cautious and do not switch on the feature you need right away. Waiting is easier when a second option is ready.
And think about refunds on the same day as payments. We wrote them two weeks later and had to fix a mistake in production.