Skip to content

Latest commit

 

History

History
391 lines (293 loc) · 14.6 KB

README.md

File metadata and controls

391 lines (293 loc) · 14.6 KB

General Payment Integration by PG

🌐 KO

Create an i'mport account following the Setup guide in the i'mport Documentation, and use the following PG integration guides to perform a test payment in each PG’s test account.

ℹ️ To better understand Korea's e-payment service flow, refer to Korean E-payment Service Flow.

The following PG integration guides cover only the contents specific to each PG. For common settings and sample codes, refer to Common PG Integration Guideline below.

Common PG Integration Guideline

1. PC/Mobile web integration

Call each PG's payment window. After the payment process is completed, post processing, such as receiving payment information, is performed through callback or redirect as follows.

ℹ️ For detailed information, refer to the General Payments guide.

ℹ️ For easy and quick integration of i'mport REST APIs, use the open source REST API client modules provided in various languages by developers using i'mport services.

1.1 Callback

  • Sample code to call the payment window via callback client-side
IMP.request_pay({
    pg : 'html5_inicis',
    pay_method : 'card',
    merchant_uid : "{Merchant created Order ID}", // Example: order_no_0001
    name : 'Order name: payment test',
    amount : 14000,
    buyer_email : '[email protected]',
    buyer_name : 'John Doe',
    buyer_tel : '010-1234-5678',
    buyer_addr : 'Shinsa-dong, Gangnam-gu, Seoul',
    buyer_postcode : '123-456'
}, function(rsp) {
    if ( rsp.success ) {
    	//[1] Pass imp_uid using jQuery ajax to retrieve payment information from the server
    	jQuery.ajax({
    		url: "/payments/complete", //Be cautious about cross-domain error
    		type: 'POST',
    		dataType: 'json',
    		data: {
	    		imp_uid : rsp.imp_uid
	    		//Add other required data as needed
    		}
    	}).done(function(data) {
    		//[2] Server-side payment amount check via REST API and service processing are successful
    		if ( everythings_fine ) {
    			var msg = 'Payment successful.';
    			msg += '\Payment ID: ' + rsp.imp_uid;
    			msg += '\nOrder ID: ' + rsp.merchant_uid;
    			msg += '\Payment amount: ' + rsp.paid_amount;
    			msg += 'Credit card authorization number: ' + rsp.apply_num;
    			
    			alert(msg);
    		} else {
    			//[3] Payment is not complete.
    			//[4] Payment amount check failed -> payment has been automatically cancelled.
    		}
    	});
    } else {
        var msg = 'Payment failed.';
        msg += 'Error: ' + rsp.error_msg;
        
        alert(msg);
    }
});
  • Pseudo code to extract payment information from Ajax POST request and perform post-processing server-side
imp_uid = extract_POST_value_from_url('imp_uid') //Get imp_uid from post ajax request

payment_result = rest_api_to_find_payment(imp_uid) //Get payment information from i'mport server using imp_uid
amount_to_be_paid = query_amount_to_be_paid(payment_result.merchant_uid) //Get original requested payment amount (associated with merchant_uid on the merchant server).

IF payment_result.status == 'paid' AND payment_result.amount == amount_to_be_paid
	success_post_process(payment_result) //Handle successful payment
ELSE IF payment_result.status == 'ready' AND payment.pay_method == 'vbank'
	vbank_number_assigned(payment_result) //Virtual account issued successfully
ELSE
	fail_post_process(payment_result) //Handle failed payment

1.2 Redirect

  • Sample code to call the payment window via redirect client-side
IMP.request_pay({
    pg : 'chai',
    pay_method : 'trans',
    merchant_uid : "{Merchant created Order ID}", // Example: order_no_0001
    name : 'Order name: payment test',
    amount : 14000,
    buyer_email : '[email protected]',
    buyer_name : 'John Doe',
    buyer_tel : '010-1234-5678',
    buyer_addr : 'Shinsa-dong, Gangnam-gu, Seoul',
    buyer_postcode : '123-456'
    m_redirect_url : '{URL to redirect to after payment approval on Mobile}' // Example: https://www.my-service.com/payments/complete/mobile
}, function(rsp) {
    if ( !rsp.success ) {
    	//When an error occurs before page is redirected to the checkout page
        var msg = 'An error occurred before initiating payment.';
        msg += 'Error: ' + rsp.error_msg;

        alert(msg);
    }
});
  • Pseudo code to extract payment information from the redirect URL's query string and perform post-processing server-side
imp_uid = extract_GET_value_from_url('imp_uid') //Get imp_uid from the query string
//merchant_uid = extract_GET_value_from_url('merchant_uid') //Get merchant_uid from the query string (optional)

payment_result = rest_api_to_find_payment(imp_uid) //Get payment information from i'mport server using imp_uid
amount_to_be_paid = query_amount_to_be_paid(payment_result.merchant_uid) //Get original requested payment amount (associated with merchant_uid on the merchant server)

IF payment_result.status == 'paid' AND payment_result.amount == amount_to_be_paid
	success_post_process(payment_result) //Handle successful payment
ELSE IF payment_result.status == 'ready' AND payment.pay_method == 'vbank'
	vbank_number_assigned(payment_result) //Virtual account issued successfully
ELSE
	fail_post_process(payment_result) //Handle failed payment

2. Mobile App WebView integration

ℹ️ For easy and quick payment integration in Android/iOS native apps, use the i'mport Mobile Native SDKs.

Use the redirect method for PC/mobile web integration to call a PG payment window from the merchant app's WebView and perform post processing after payment approval.

For iOS, to return to the merchant app after payment approval, you need to specify the merchant app scheme value in the param.app_scheme parameter of the (IMP.request_pay(param, callback)) function.

app_scheme supports the following two formats:

  • iamporttest: specify URL scheme only (iamporttest:// called).
  • iamporttest://path?query: specify parameter to receive from payment app (called as is)
IMP.request_pay({
	/*...Omitted... */
	app_scheme: 'iamporttest' // merchant app's URL scheme
})

Payment approval requires configuration and implementation for navigating between apps as follows:

  1. Merchant app -> payment app
  2. Payment app -> merchant app

2.1 Merchant app -> payment app

Key payment app URL schemes
URL Scheme App
ansimclick Samsung Card - Online Payment
ansimclickipcollect Samsung Card - Online Payment
ansimclickscard Samsung Card - Online Payment
chaipayment CHAI app
citicardappkr Citi Card - Certification App
citimobileapp Citi Card - Simple Pay
citispay Citi Card-App Card
cloudpay Hana Card-App Card
com.wooricard.wcard Woori WON Pay
hanamopmoasign Hana Card - Certification App
hanawalletmembers Hana Card-Hana Members Wallet
hdcardappcardansimclick Hyundai Card-App Card
hyundaicardappcardid Hyundai Card
ispmobile ISP Mobile
itms-apps App Store
kakaotalk Kakao Pay
kb-acp Kookmin Card-App Card
kb-auth Kookmin
kftc-bankpay Account transfer
lguthepay-xpay Paynow
liivbank Kookmin Liiv M (Liiv Mobile)
lmslpay Lotte L.pay App
lotteappcard Lotte Card-App Card
lottesmartpay Lotte Card - Mobile Payment
Lpayapp (Old) Lotte L.pay App
mpocket.online.ansimclick Samsung Card-App Card
NewSmartPib Woori WON Banking
nhallonepayansimclick Nonghyup-All One Pay
nhappcardansimclick Nonghyup-App Card
nonghyupcardansimclick Nonghyup Card - Certification App
payco Payco
samsungpay Samsung Card-Samsung Pay
scardcertiapp Samsung Card-Certificate
shinhan-sr-ansimclick Shinhan Card-App Card
smhyundaiansimclick Hyundai Card - Certification App
smshinhanansimclick Shinhan Card - Certification App
supertoss Toss
vguardstart Samsung Card - Vaccine
wooripay Woori Card-App Card

2.1.a Android

In the WebView of the merchant app, implement logic to call each PG's payment app and check if the app is installed.

Override the shouldOverrideUrlLoading method of the WebViewClient class as follows:

public class MyViewClient extends WebViewClient {

	@Override
	public boolean shouldOverrideUrlLoading(WebView view, String url) {
		if (!url.startsWith("http://") && !url.startsWith("https://") && !url.startsWith("javascript:")) {
			// Call payment app based on the URL scheme
			Intent intent = null;

			try {
				intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); //Process IntentURI
				Uri uri = Uri.parse(intent.getDataString());

				activity.startActivity(new Intent(Intent.ACTION_VIEW, uri));
				return true;
			} catch (URISyntaxException ex) {
				return false;
			} catch (ActivityNotFoundException e) {
				if ( intent == null )	return false;

				// If payment app is not installed, redirect to Android market
				if ( handleNotFoundPaymentScheme(intent.getScheme()) )	return true;

				// If not handled by handleNotFoundPaymentScheme() but package info can be retrieved from the URL, redirect to Android  market
				String packageName = intent.getPackage();
				if (packageName != null) {
					activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
					return true;
				}

				return false;
			}
		}
	}
}

2.1.b iOS

No additional processing is required to open a payment app. If you register the app in the white-list, you will be directed to the payment app through a confirmation popup.

According to the iOS security policy, you must declare the URL scheme of the payment app by adding the LSApplicationQueriesSchemes key to the info.plist file to show a confirmation popup.

<key>LSApplicationQueriesSchemes</key>
<array>
	<string>kftc-bankpay</string>
	...
</array>

2.2 Payment app -> merchant app

When payment is completed in the payment app, you can return to the merchant app by calling the URL scheme declared in the merchant app.

2.2.a Android

Android automatically switches to the previous activity when the current Activity is popped from the Activity Stack (Task). Hence, there is no need to declare or process the URL scheme of the merchant app.

2.2.b iOS

Declare merchant app's URL scheme

Add the merchant app_scheme in the Build Info tab of XCode.

Xcode Capture

<key>CFBundleURLSchemes</key>
<array>
	<string>iamporttest</string>
</array>

2.3 Cookie Settings

Cookies may be used to integrate between PG and credit card modules. For seamless payment processing, add the following code in the WebView.

2.3.a Android

Sample code

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
	mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
	val cookieManager = CookieManager.getInstance()
	cookieManager.setAcceptCookie(true)
	cookieManager.setAcceptThirdPartyCookies(webView, true)
}

2.3.b iOS

Sample code

HTTPCookieStorage.shared.cookieAcceptPolicy = HTTPCookie.AcceptPolicy.always

2.4 Show alert/confirm popup

To show alert/confirm popups that occur in the WebView's web page, you must implement the logic to show each popup as an Android or iOS popup.

2.4.a Android

To show alert/confirm popup, override the following methods of the WebChromeClient class.

  • Alert: onJsAlert
  • Confirm: onJsConfirm

Sample code

2.4.b iOS

Implement the following functions of the WKUIDelegate protocol, which is called when alert/confirm popup occurs in the web page.

  • Alert: webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage:, initiatedByFrame:, completionHandler:)
  • Confirm: webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage:, initiatedByFrame:, completionHandler:)

Alert sample code

Confirm sample code