Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2-та класа които отварят webview (android, ios) и го конфигурират да приема самоподписани (unsecure) https страници, които се ползват само в дебъг
- адресите които получават са:
- при DEBUG: https://mdpay-test.fibank.bg/ecomm/ClientHandler?trans_id=1231231
- при RELEASE: https://mdpay.fibank.bg/ecomm/ClientHandler?trans_id=
- (trans_id се взима след заявка към urbo сървъра (makeOrder заявка))
- // ANDROID
- package com.urboapp.android.urbo.view.parking;
- import android.content.DialogInterface;
- import android.graphics.Bitmap;
- import android.net.http.SslError;
- import android.os.Bundle;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.content.Intent;
- import android.webkit.SslErrorHandler;
- import android.webkit.WebResourceRequest;
- import android.webkit.WebSettings;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- import com.urboapp.android.urbo.R;
- public class CardEntryActivity extends AppCompatActivity {
- public static final int SUCCESS = 13;
- public static final int FAILURE = 14;
- public long parkingStart;
- public long orderId;
- void dismissWithResult(int result) {
- Intent data = new Intent();
- data.putExtra("PARKING_START", parkingStart);
- data.putExtra("ORDER_ID", orderId);
- setResult(result, data);
- finish();
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_card_entry);
- WebView myWebView = (WebView) findViewById(R.id.webview);
- WebSettings webSettings = myWebView.getSettings();
- webSettings.setJavaScriptEnabled(true);
- myWebView.setWebViewClient(new WebViewClient() {
- @Override
- public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(CardEntryActivity.this);
- builder.setMessage("The SSL certificate of this page is invalid. Do you want to proceed anyway?");
- builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- handler.proceed();
- }
- });
- builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- handler.cancel();
- dismissWithResult(FAILURE);
- }
- });
- final AlertDialog dialog = builder.create();
- dialog.show();
- }
- @Override
- public void onPageFinished(WebView view, String url) {
- if (url.contains("frantishex")) {
- if (url.contains("success"))
- dismissWithResult(SUCCESS);
- else
- dismissWithResult(FAILURE);
- }
- }
- });
- // Get the Intent that started this activity and extract the string
- Intent intent = getIntent();
- String url = intent.getStringExtra("CARD_ENTRY_URL");
- parkingStart = intent.getLongExtra("PARKING_START", 0);
- orderId = intent.getLongExtra("ORDER_ID", 0);
- myWebView.loadUrl(url);
- }
- }
- /// IOS
- import UIKit
- class CardEntryViewController: UIViewController, UIWebViewDelegate, NSURLConnectionDelegate {
- @IBOutlet weak var closeButton: UIButton!
- @IBOutlet weak var webView: UIWebView!
- enum PaymentResult: Int {
- case success = 0
- case cancel = 1
- case failed = 2
- }
- typealias CompletionBlock = (_ result: PaymentResult) -> Void
- var urlString: String?
- var orderId: Int?
- var completeHandler: CompletionBlock?
- override func viewDidLoad() {
- super.viewDidLoad()
- if let urlString = self.urlString {
- let url = URL(string: urlString)
- NSLog("bank payment request: %@", urlString)
- let urlRequest = URLRequest(url: url!)
- let urlConnection:NSURLConnection = NSURLConnection(request: urlRequest, delegate: self)!
- urlConnection.start()
- webView.loadRequest(urlRequest)
- webView.delegate = self
- }
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- func webView(_ view: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
- return true
- }
- func connection(_ connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: URLProtectionSpace) -> Bool{
- return true
- }
- @IBAction func didPressColoseButton(_ sender: Any) {
- //self.dismiss(animated: true, completion: nil)
- if let closeHandler = completeHandler {
- closeHandler(PaymentResult.cancel)
- }
- }
- func webViewDidFinishLoad(_ webView: UIWebView) {
- let href = webView.stringByEvaluatingJavaScript(from: "window.location.href")
- if let url = href {
- if url.lowercased().range(of:"frantishex") != nil {
- if url.lowercased().range(of:"success") != nil {
- if let closeHandler = completeHandler {
- closeHandler(PaymentResult.success)
- }
- }
- else {
- if let closeHandler = completeHandler {
- closeHandler(PaymentResult.failed)
- }
- }
- }
- }
- }
- func connection(_ connection: NSURLConnection, didReceive challenge: URLAuthenticationChallenge){
- if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
- let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
- challenge.sender!.use(credential, for: challenge)
- } else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodHTTPBasic {
- let defaultCredentials: URLCredential = URLCredential(user: "username", password: "password", persistence:URLCredential.Persistence.forSession)
- challenge.sender!.use(defaultCredentials, for: challenge)
- } else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodNTLM {
- } else{
- challenge.sender!.performDefaultHandling!(for: challenge)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement