Partnering with The Codero for complete digital payment gateway solutions

We have some great news to share with all of you. As you know we are continuously working to improve our solutions and service offering for our customers that we promised. Our entire journey depends on how we serve for our customers to develop their business rapidly with consistent improvement with our services. Today I am going to announce you a very exciting news.

 

 

Preview Technologies Limited has signed a MoU with The Codero Limited. The Codero Limited has a set of digital payment gateway solutions and specially one of their base payment gateway solutions “EasyPayWay” is now available for all of our new and existing customers who was just waiting to integrate digital payment gateway with their e-commerce website and get payment from mostly all kinds of payment system like bKash, Rocket, Credit/Debit Cards and Online Banking. This partnership is a great opportunity for Preview Technologies Limited to develop more easy, efficient and customized payment gateway solutions. Here is a solution snapshots I can’t wait to tell you.

Faster Merchant ID Create & Approval Process
All of our new and existing customer can now apply for getting a merchant account to get payment from their clients with debit/credit card, online banking and other popular payment providers.
This usually takes longer period of time to get merchant approval with lots of paperwork. But from now on, Preview Technologies Limited can process all merchant application with our partner The Codero Limited more quickly and efficiently.

Lowest Transaction Fees
We are still working to get it fixed and we will announce the transactions fees and registration pricing later but due to this partnership agreement we can now guarantee the lowest transaction and processing fees for our customers.

All Bangladeshi Popular Payment Method Supported
EasyPayWay, a solutions provided by The Codero Limited has a wide range of popular payment methods including bKash, Rocket, QCash, MCash, DBBL Nexus, Visa, MasterCard, JCB, City Bank, Payza, IFIC Mobile Banking, Discover, FastCash, etc.

 

Dedicated Dashboard With Extended Reporting
EasyPayWay will provide a dedicated dashboard to all of our customers where you can explore all kinds of payment and transaction related activity including, managing transaction, refund processing, withdraw request to bank, etc.

Extensive API Integration & Customization
EasyPayWay will provide a wide range of integration and customization features such as plugins, libraries, SDKs for all of our customers for better integration with existing system that we develop. Though, Preview Technologies Limited will help all of it’s customers to integrate payment gateway with their system that you shouldn’t worry about.

So ultimately, I couldn’t wait to share this extremely exciting news with you. On behalf of Preview Technologies Limited I can ensure a great flexible, efficient, reliable payment gateway solutions for all of our new and existing customers. Also besides expressing this news with all of you, I want to personally thanks to Mr. Riad and Mr. Rana from The Codero Limited team to make this happen and on behalf of our entire Preview Technologies family we hope for a greater future for both of our business in every way we can perform together.

Cheers!

Get OAuth 2.0 access token using Retrofit 2.x

Retrofit is an awesome and easy to use library. You can use Retrofit for any Android or Java application which need to interact with our OAuth2.0 server to get access token.

You just need to build the retrofit properly to get it done. It doesn’t require any advance knowledge. Let’s see how it can be done easily.

To get the access token using Retrofit we need to do –

Add Retrofit in your project via Maven or Gradle. Complete installation guide can be found here.

Now let’s create the Retrofit builder. And before doing that we need to create a service interface.

//AccessTokenServiceInterface.java
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

public interface AccessTokenServiceInterface {

    @POST("/oauth/v1/access_token")
    @FormUrlEncoded
    Call<TokenResponse> getToken(@Field("client_id") String client_id, @Field("client_secret") String client_secret, @Field("scope") String scope, @Field("grant_type") String grant_type);
}

And now the builder.

//Http.java
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import java.io.IOException;

public class Http {
    public static void main(String[] args) {
        Retrofit retrofit = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl("https://myaccount.previewtechs.com")
                .build();

        AccessTokenServiceInterface service = retrofit.create(AccessTokenServiceInterface.class);

        //grant types = client_credentials
        Call<TokenResponse> call = service.getToken("OAUTH CLIENT ID", "OAUTH CLIENT SECRET", "basic email", "client_credentials");
        try {
            Response<TokenResponse> response = call.execute();
            System.out.println(response.body().getAccessToken());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

And also we need to map the JSON response from our OAuth 2.0 server. So we need a model to map that. Let’s create TokenResponse.java model class

//TokenResponse.java
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class TokenResponse {

    @SerializedName("token_type")
    @Expose
    private String tokenType;
    @SerializedName("expires_in")
    @Expose
    private Integer expiresIn;
    @SerializedName("access_token")
    @Expose
    private String accessToken;

    public String getTokenType() {
        return tokenType;
    }

    public void setTokenType(String tokenType) {
        this.tokenType = tokenType;
    }

    public Integer getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(Integer expiresIn) {
        this.expiresIn = expiresIn;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

}

Now run Http.main and you will get your access token.

That’s it. Now run the Http.main and you will get the access token easily. Download these scripts from our PreviewTechnologies/access-token-retrofit GitHub repository.

This article also available on our support portal.

cURL vs “file_get_contents()” in Google App Engine – Performance analysis

We all know that to do any kinds of external HTTP request from your PHP application (deployed in Google App Engine a.k.a GAE) we have three options basically. PHP native cURL extension, “cURL Lite” provided by Google and the native http:// and https:// PHP stream handlers.

cURL requires a valid billing profile and only you can enable it in your Google Cloud paid project. And that’s why Google’s custom cURL Lite actually use Google’s urlfetch service that you can use in your application free version.

But recent days, our engineering team was just wondering which can be little bit faster among cURL or cURL Lite or PHP native PHP HTTP handler, in this sense little bit faster meaning we also count even 50ms latency. That’s why I was running some test with a single script hosted on Google App Engine (PHP Standard Runtime environment). We had lots of PHP microservice apps hosted on Google App Engine and all services at a certain time needs to talk each other via HTTP external request. But sometimes, we were aware that latency is killing some communication.

So we just built 2 files basically in PHP. One is using cURL to post some foobar json data to an external URL (postb.in) and another one was using the native http:// and https:// PHP stream handlers. Let’s see what was our experimental scripts look like.

<?php

/**
 * Using CURL
 */

$data = array("foo" => "bar");
$data_string = json_encode($data);

$ch = curl_init('http://postb.in/xxxxxx');
//$ch = curl_init('/post.php');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string)
    )
);

$result = curl_exec($ch);
<?php

/**
 * php_http_stream.php
 *
 * using cURL lite. It use google's urlfetch service
 */

$url = 'http://postb.in/xxxxxx';
$data = array("foo" => "bar");
$data_string = json_encode($data);

$contentLength = strlen($data_string);

$headers = "accept: */*\r\n" .
    "Content-Type: application/json\r\n" .
    "Content-Length: $contentLength\r\n";

$context = [
    'http' => [
        'method' => 'POST',
        'header' => $headers,
        'content' => $data_string,
    ]
];
$context = stream_context_create($context);
$result = file_get_contents($url, false, $context);

And here is the trace report of those two call.

@0 ms
/php_http_stream.php
Summary
Name			RPCs	Total Duration (ms)
/curl_lite.php		1	450
/urlfetch.Fetch		1	333
Details
Timestamp		xxxx-xx-xx (xx:xx:xx.xxx)
Traced time 		333 ms
Untraced time 		117 ms

http/response/size	25
@0 ms
/curl.php
Summary
Name				RPCs	Total Duration (ms)
/curl.php			1	753
/remote_socket.Close		4	4
/remote_socket.Connect		10	157
/remote_socket.CreateSocket	4	10
/remote_socket.GetSocketOptions	1	1
/remote_socket.Poll		10	469
/remote_socket.Receive		2	2
/remote_socket.Send		2	2
/remote_socket.SetSocketOptions	1	1
Details
Timestamp	2017-xx-xx (xx:xx:xx.xxx)
Traced time 	646 ms
Untraced time 	107 ms

http/response/size		25

So what does it mean to you? It means a lot for me. Obviously cURL Lite is saving me couple milliseconds. And also I don’t need to be afraid of my “socket operation” quota that was used in cURL.

So in this, what should I say? file_get_contents() is more optimized? Of course, I am just talking how it’s performing for little external URL call with Google’s urlfetch service.

So if your application needs to interact with external service with less configuration and options, then I would prefer to use native PHP HTTP stream handler and make all external http call with file_get_contents() function. file_get_contents() use urlfetch service and you don’t need to enable cURL extension in your application.

Train your engineering workforce for using Cloud services

Everybody is talking about Cloud. Cloud and Cloud. Major tech giants are very busy for their Cloud PaaS (Platform as a Service) services including Google, Amazon, Azure, IBM and so on. There are lots of player are playing this game to takeover cloud market share. According to Right Scale blog post about their survey,

68 percent of enterprises run less than a fifth of their application portfolios in the cloud. 55 percent of enterprises report that a significant portion of their existing application portfolios are not in cloud, but are built with cloud-friendly architectures. It’s amazing. Everybody is preparing for Cloud

– Right Scale Blog

So why not you. As the cloud service market will grow with competition consumer will be much benefited. It’s simple calculation. Recently I monitored AWS, Google Cloud monthly update for their Cloud service. And I realized that every month most of the cloud service provider are releasing on avg. 10-15 new products and continuously improving their existing products. That’s a very good sign that they are expecting more people to go for cloud.

goldman-sachs-cloud-computing1

As much as I read about cloud I am feeling amazing as an engineering perspective. If we go few years back, as a software engineer always it was a hassle to deploy service for public, managing theme, upgrading them, automate the workflow. But now cloud made all those things so much easier even I can save my 40-50 hours after every project my team finish and I can become a more worry-less person than ever before. At Preview Technologies HQ, we officially announced that “we are going cloud and we are preparing resources for our existing customers also to become cloud friendly”. 50% of our engineering workforce are now getting training about cloud services and we are encouraging them about the necessity of going cloud.

cloud-computing-trends-public-cloud-usage-2015-1

Our business is heavily web application development service based and most of our clients are business institutions. So it’s not easy to bring all of them on board but we are trying and after our engineering team training we are planning to run massive campaign for our business clients about cloud. We never preferred any specific cloud service provider but also we start providing our clients to chose their best cloud providers and we can work with them. Currently most of our clients can choose between Google Cloud, AWS. As we go further, this list will be extended. All software and technology companies should start train their engineering workforce to practice cloud service and if they start doing that from right now, they must be benefited in near future cause clients are also becoming more smarter than before. They want cloud. Some clients are obsessed with this word CLOUD. So if you have a business or you are a leader among your engineering team, it’s time to be trained up and getting ready for cloud.

 

Using custom domain to Google App Engine with custom routing

Adding custom domain to Google App Engine is pretty straight-forward and easy to implement.

But there are some complexities around it when you want to point your custom domain or sub-domain to any specific service or module in Google App Engine. In your Google Cloud project you can have multiple App Engine service. By default your first app engine app will be considered as “default” service. Rest of the apps must need to be on another service or module. So the main use case scenario is, suppose you have a sub-domain “office-api.yourdomain.com” and you want to point that in your App Engine’s “office-api” service.

Then you can’t do that because if you point your “yourdomain.com” to Google App Engine then you can’t use that domain for your other purposes. Google will use that domain to point all services, default, custom, etc..

But if you want to use your primary business domain inside App Engine like your corporatebusiness.com domain then what you will do. You have hosted your website in this domain in another server, you have another services hosted on that domain. But for better personalized sub-domain you want to use that same doamain’s sub-domain in Google App Engine.

Here is the steps about how you can configure your sub-domain directly pointed to any specific service.

First,
You need to add your custom domain to Google App Engine from App Engine -> Settings -> Custom Domain.

app-engine-domains-previewtechs-gc-us-central-1a

Now you need to add your custom domain and need to verify your domain name. Google has a very easy way with instruction to do that. Now from your domain registrar, you need to just change your CNAME pointed to ghs.googlehosted.com domain. Only CNAME, cause you are using this domain for your other services. Only this specific sub-domain will be used in Google App Engine.

After doing that you are done! Now google has it’s own routing policy to route your application based on service-id.yourcustomsub-domain.com but you want to customized that in your way. And you can do that by appcfg.py command line python tools. You can learn that directly from https://cloud.google.com/appengine/docs/python/how-requests-are-routed#routing_via_url . Now in your dispatch file write the following configuration.

dispatch:
  - url: "office-api.businessdomain.com/*"
    module: office-api

And upload this dispatch file with the appcfg.py command line utilities. Documentations are available https://cloud.google.com/appengine/docs/python/config/dispatchref. Now you have your official homepage hosted on www.businessdomain.com and office-api.businessdomain.com is pointed to Google App Engine custom services. Now browse your office-api.businessdomain.com url and you will see your application. Thanks.