2017-03-25 64 views
1

我已经创建了一个应用程序。现在我想在我的应用程序中整合韩国付款之旅Iamport。我在开发者平台上阅读了整个documentation。我已检查example代码已在github但我仍然没有得到确切的解决方案。如何集成Iamport韩国支付网关?

问题: - 我没有得到的是如何与我的应用程序集成,因为在该演示中只有一个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); 
     } 
    } 

} 

回答

2

如果你读了那么完美已经规定在stets如何整合支付网关。

让我解释一下你一步一步的一切::

第1步::

转到与此第一URL,并创建自己的帐户和登录。 然后您将获得API KEYAPI SECRET KEY,然后打开PG setting (authentication method payment)选项卡并将其保留在您的SendBox(ON表示您的支付网关处于测试模式,OFF表示您的支付网关处于活动状态)。

步骤2 ::

复制IamPort SDK从HERE,并与您的项目整合。

步骤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); 
     } 
    } 

} 

步骤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(); 
     } 



    } 

} 

步骤-5 ::

付款。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 : '[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> 

创建另一个文件,您可以在其中接收付款状态。

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> 

步骤-6 ::

如果您需要检查通过API付款再检查here。 使用API_KEYAPI SECRET_KEY获取令牌。然后在使用该令牌和imp_uid号码后,您将获得付款的所有细节。

我希望你能得到你的解决方案。我可以知道你是否需要任何东西。

+0

1+非常感谢您发布此答案。它的魅力。 – Shailesh