Issue
I have created one app. Now i want to integrate Iamport korean payment getaway in my app. I have read the whole documentation on developer portal. I have checked example code which is already in github
but i am still not getting exact solution.
Problem:-
I am not getting that how to integrate with my app, because in that demo there is only one URL
. Means i am not getting exact flow of payment gateway. can anyone give solution step by step. so i can understand perfectly. i am trying to implement this last 2 weeks and now i stucked.
I done the following code.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.zennaxx.iamportpay.MainActivity">
<WebView
android:id="@+id/mainWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity {
private WebView mainWebView;
private static final String APP_SCHEME = "iamporttest://";
@SuppressLint("NewApi") @Override
protected void onCreate(Bundle savedInstanceState) {
super . onCreate (savedInstanceState);
setContentView(R.layout.activity_main);
mainWebView = (WebView) findViewById(R.id.mainWebView);
mainWebView . setWebViewClient ( new InicisWebViewClient ( this ));
WebSettings settings = mainWebView . getSettings ();
settings.setJavaScriptEnabled(true);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager . setAcceptCookie ( true );
cookieManager . setAcceptThirdPartyCookies (mainWebView, true );
}
Intent intent = getIntent();
Uri intentData = intent.getData();
if ( intentData == null ) {
mainWebView.loadUrl("myUrl");
} else {
// When returning after payment follow-up Certification isp
String url = intentData.toString();
if ( url.startsWith(APP_SCHEME) ) {
String redirectURL = url.substring(APP_SCHEME.length()+3);
mainWebView.loadUrl(redirectURL);
}
}
}
@Override
protected void onNewIntent ( Intent intent ) {
String url = intent.toString();
if ( url.startsWith(APP_SCHEME) ) {
String redirectURL = url.substring(APP_SCHEME.length()+3);
mainWebView.loadUrl(redirectURL);
}
}
}
Solution
If you read perfectly then already specified in that stets how to integrate payment gateway.
Let me explain you everything step by step ::
Step-1 ::
Go with this first URL and create your own account and login.
then you will get API KEY
and API SECRET KEY
and then after open PG setting (authentication method payment)
tab and keep it on your SendBox
(ON means your payment gateway is on testing mode and OFF means your payment gateway is live).
Step-2 ::
Copy IamPort SDK from HERE and integrate with your project.
Step-3 ::
Put this code as it :
public class MainActivity extends Activity {
private WebView mainWebView;
private static final String APP_SCHEME = "iamporttest://";
@SuppressLint("NewApi") @Override
protected void onCreate(Bundle savedInstanceState) {
super . onCreate (savedInstanceState);
setContentView(R.layout.activity_main);
mainWebView = (WebView) findViewById(R.id.mainWebView);
mainWebView . setWebViewClient ( new InicisWebViewClient ( this ));
WebSettings settings = mainWebView . getSettings ();
settings.setJavaScriptEnabled(true);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager . setAcceptCookie ( true );
cookieManager . setAcceptThirdPartyCookies (mainWebView, true );
}
Intent intent = getIntent();
Uri intentData = intent.getData();
if ( intentData == null ) {
//payment.html file is below
mainWebView.loadUrl("https://yourdomain/API/payment.html");
} else {
// When returning after payment follow-up Certification isp
String url = intentData.toString();
if ( url.startsWith(APP_SCHEME) ) {
String redirectURL = url.substring(APP_SCHEME.length()+3);
mainWebView.loadUrl(redirectURL);
}
}
}
@Override
protected void onNewIntent ( Intent intent ) {
String url = intent.toString();
if ( url.startsWith(APP_SCHEME) ) {
String redirectURL = url.substring(APP_SCHEME.length()+3);
mainWebView.loadUrl(redirectURL);
}
}
}
Step-4 ::
Override onPageFinished()
Method like this and make related changes after read below code.
public class InicisWebViewClient extends WebViewClient {
public static final String TAG = "[InicisWebViewClient]";
private Activity activity;
String imp_uid = "", merchant_uid = "", imp_success = "", error_msg = "", paymentStatusRecUrl = "",
apply_num = "";
public InicisWebViewClient(Activity activity) {
this.activity = activity;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (!url.startsWith("http://") && !url.startsWith("https://") && !url.startsWith("javascript:"))
{
Intent intent = null;
try {
//Intent URI process
Log.e(TAG, "in side try block...");
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
Uri uri = Uri.parse(intent.getDataString());
//Run the appropriate Activity
activity.startActivity(new Intent(Intent.ACTION_VIEW, uri));
return true;
} catch (URISyntaxException ex) {
return false;
} catch (ActivityNotFoundException e) {
if ( intent == null )
return false;
// Pre-processing for non-installed apps (such as moving Google Play)
if ( handleNotFoundPaymentScheme(intent.getScheme()) )
return true;
String packageName = intent.getPackage();
if (packageName != null) {
// If you have packageName, search on Google Play
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
return true;
}
return false;
}
}
return false;
}
/**
* @param scheme
* @return Whether to process the scheme directly
*
* Processes if ActivityNotFoundException occurs because 3rd party app for billing is not yet installed.
* If you can extract package information from an intent for a scheme that is not handlered here, then move to market as packageName from the following.
*
*/
protected boolean handleNotFoundPaymentScheme(String scheme) {
//If you do not run the market after an ActivityNotFoundException occurs because there is no package information in the url that the PG calls
if ( PaymentScheme.ISP.equalsIgnoreCase(scheme) ) {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + PaymentScheme.PACKAGE_ISP)));
return true;
} else if ( PaymentScheme.BANKPAY.equalsIgnoreCase(scheme) ) {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + PaymentScheme.PACKAGE_BANKPAY)));
return true;
}
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.e("[InicisWebViewClient]", "onPageFinished() url = " + url);
String receivedFinishURL = url;
String paymentStatusUrl = null;
try {
paymentStatusUrl = getDomainName(receivedFinishURL);
Log.e(TAG, "paymentStatusUrl = " + paymentStatusUrl.toString());
if (paymentStatusUrl.equals("https://yourdomain/API/paymentStatus.html")) // Write here redirected URL which you have set in JavaScript File
{
paymentStatusRecUrl = receivedFinishURL;
List<NameValuePair> params = URLEncodedUtils.parse(new URI(receivedFinishURL), "UTF-8");
for (NameValuePair param : params) {
if ("imp_uid".equals(param.getName()))
{
imp_uid = param.getValue();
}
else if ("merchant_uid".equals(param.getName()))
{
merchant_uid = param.getValue();
}
else if ("imp_success".equals(param.getName()))
{
imp_success = param.getValue();
}
else if ("error_msg".equals(param.getName()))
{
error_msg = param.getValue();
}
else if ("apply_num".equals(param.getName()));
{
apply_num = param.getValue();
}
}
Log.e(TAG, "received paged data...........");
Log.i(TAG, "imp_uid = " + imp_uid);
Log.i(TAG, "merchant_uid = " + merchant_uid);
Log.i(TAG, "imp_success = " + imp_success);
Log.i(TAG, "error_msg = " + error_msg);
Log.i(TAG, "apply_num = " + apply_num);
if (imp_success.equals("true"))
{
// If your payment will success then your cursore comes here
//if your payment is successful then you can start your new activity and design as per your requirement.
}
else if (imp_success.equals("false"))
{
// If your payment will cancelled then your cursore comes here
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
Step-5 ::
payment.html
you have to Implement your Script file like below but this is sample file you have to implement as per your requirement.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Payment Demo</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js" ></script>
<script type="text/javascript" src="https://service.iamport.kr/js/iamport.payment-1.1.2.js"></script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<style>
.goog-logo-link {
display:none !important;
}
.goog-te-gadget{
color: transparent !important;
}
.goog-te-gadget .goog-te-combo{color:#000 !important;}
</style>
<script>
function callme()
{
IMP.init('yourIMPCredential');
payRequest();
}
function payRequest()
{
//you can set your value accordinglly by using simple domcument.getElementById().value
IMP.request_pay({
pg : 'inicis', // version 1.1.0.
pay_method : 'card',
merchant_uid : 'merchant_' + new Date().getTime(),
name : 'This is My name',
amount : 1000,
buyer_email : '[email protected]',
buyer_name : 'This is buyer name',
buyer_tel : '010-1234-5678',
buyer_addr : 'This is buyer email',
buyer_postcode : '123-456',
m_redirect_url : 'https://yourdomain/API/payment.html'//here you can specified your URL
}, function(rsp) {
if ( rsp.success ) {
var msg = 'Succeess message.';
msg += 'response_id: ' + rsp.imp_uid;
msg += 'response_merchant_id : ' + rsp.merchant_uid;
msg += 'response_paid_amount: ' + rsp.paid_amount;
msg += 'rsp.apply_num: ' + rsp.apply_num;
} else {
var msg = 'Failure message.';
msg += 'rsp.error_msg: ' + rsp.error_msg;
}
alert(msg);
});
}
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
//goog-te-combo
}
</script>
</head>
<body>
<div id="google_translate_element" style="text-align:center;"></div>
<div class="container">
<div class="row">
<div class="col-md-12" id="alertmsg"></div>
<!-- panel preview -->
<div class="col-sm-3"></div>
<div class="col-sm-6">
<h4>I'mport; Payment module DEMO</h4>
<div class="panel panel-default">
<form name="frm" method="post" id="frm">
<div class="panel-body form-horizontal payment-form">
<div class="form-group">
<label for="date" class="col-sm-3 control-label">Payment Name</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="name" name="name" value="paymentName">
</div>
</div>
<div class="form-group">
<label for="order_number" class="col-sm-3 control-label">Order Number</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="order_number" name="order_number" value="1234">
</div>
</div>
<div class="form-group">
<label for="ticket_name" class="col-sm-3 control-label">Ticket Name</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="ticket_name" name="ticket_name" value="ticket_1234">
</div>
</div>
<div class="form-group">
<label for="amount" class="col-sm-3 control-label">Amount</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="amount" name="amount" value ="1000">
</div>
</div>
<div class="form-group">
<label for="buyer_email" class="col-sm-3 control-label">Buyer Email</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="buyer_email" name="buyer_email" value="[email protected]">
</div>
</div>
<div class="form-group">
<label for="buyer_name" class="col-sm-3 control-label">Buyer Name</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="buyer_name" name="buyer_name" value="Tester">
</div>
</div>
<div class="form-group">
<label for="buyer_phone_number" class="col-sm-3 control-label">Buyer Phone Number</label>
<div class="col-sm-9">
<input type="tel" class="form-control" id="buyer_phone_number" name="buyer_phone_number" value="0129384756">
</div>
</div>
<div class="form-group">
<label for="buyer_tel" class="col-sm-3 control-label">Virtual account deposit date</label>
<div class="col-sm-9">
<input type="date" class="form-control" id="vbank_due" name="vbank_due">
</div>
</div>
<div class="form-group">
<div class="col-sm-12 text-right">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<button class='form-control btn btn-primary' type='submit' onclick="callme();"> Pay Now </button>
</div>
<div class="col-sm-3"></div>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="col-sm-3"></div>
</div>
</div>
</body>
</html>
Create one another file where you can receive your payment status.
paymentStaus.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Payment status</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js" ></script>
<style>
</style>
<script>
</script>
</head>
<body>
<div style="text-align:center;"></div>
<div class="container">
<div class="row">
<div class="col-md-12" id="alertmsg"></div>
<!-- panel preview -->
<div class="col-sm-3"></div>
<div class="col-sm-6">
<h4>I'mport; Payment module Finish</h4>
<div class="panel panel-default">
<form name="frm" method="post" id="frm">
<div class="panel-body form-horizontal payment-form">
<div class="form-group">
<div class="col-sm-12 text-right">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<button class='form-control btn btn-primary' type='submit' > Finish </button>
</div>
<div class="col-sm-3"></div>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="col-sm-3"></div>
</div>
</div>
</body>
</html>
Step-6 ::
If you need to check your payment by using API then check here.
Use API_KEY
and API SECRET_KEY
for get token. Then after using that token and imp_uid
number you will get all the detail of your payment.
I hope you will get your solution.May i know if you need anything.
Answered By - Kunal Vaja
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.