我已经创建了一个应用程序。现在我想整合 Iamport我的应用程序中的韩国支付逃亡。我已阅读全文 documentation在开发者门户网站上。我检查了example已经在 github
中的代码,但我仍然没有得到确切的解决方案。
问题:-
我不知道如何与我的应用程序集成,因为在该演示中只有一个 URL
。意味着我没有得到支付网关的确切流程。任何人都可以逐步给出解决方案。所以我完全可以理解。过去 2 周我一直在努力实现这一点,但现在我卡住了。
我完成了以下代码。
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);
}
}
}
最佳答案
如果您阅读得很好,那么在 stets 中已经指定了如何集成支付网关。
让我一步步向您解释一切::
Step-1 ::
首先使用 URL 并创建您自己的帐户并登录。
然后你会得到API KEY
和API SECRET KEY
然后打开PG setting (authentication method payment)
标签并保存在你的SendBox
(ON 表示您的支付网关处于测试模式,OFF 表示您的支付网关已上线)。
Step-2 ::
从 HERE 复制 IamPort SDK 并与您的项目集成。
Step-3 ::
把这段代码写成:
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 ::
覆盖onPageFinished()
这样的方法,阅读下面的代码后进行相关更改。
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
您必须像下面那样实现您的脚本文件,但这是您必须根据您的要求实现的示例文件。
<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 : 'this_is_buyer_email@gmail.com',
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="text@gmail.com">
</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>
创建另一个文件,您可以在其中接收付款状态。
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 ::
如果您需要使用 API 检查您的付款,请检查 here 。
使用 API_KEY
和 API SECRET_KEY
获取 token 。然后在使用该 token 和 imp_uid
号码后,您将获得付款的所有详细信息。
我希望你能得到你的解决方案。我可以知道你是否需要任何东西。
关于android - 如何集成 Iamport 韩国支付网关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43015108/