Skip to content

Commit

Permalink
Release 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement authored and Clement committed Sep 26, 2016
1 parent 5586f66 commit b406c6b
Show file tree
Hide file tree
Showing 31 changed files with 489 additions and 45 deletions.
78 changes: 78 additions & 0 deletions MOLPayExtensionForAndroid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Text;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Webkit;
using Android.Widget;
using Android.Util;
using System.IO;
using Android.Media;

using MPayXDKExample.Droid;
using MPayXDKExample;

[assembly: Xamarin.Forms.Dependency(typeof(MPExtension))]

namespace MPayXDKExample.Droid
{
public class MPExtension : MOLPayExtension
{
private static Object molpayActivity;

public void SetMOLPayContext(Object mpActivity)
{
molpayActivity = mpActivity;
}

public String GetAssetPath()
{
return "file:///android_asset/";
}

public void saveImageToDevice(String base64ImageString, String filename)
{
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, base64ImageString = {0}", base64ImageString);
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, filename = {0}", filename);

byte[] imageAsBytes = Base64.Decode(base64ImageString, Base64Flags.Default);
Bitmap bitmap = BitmapFactory.DecodeByteArray(imageAsBytes, 0, imageAsBytes.Length);

var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
var filePath = System.IO.Path.Combine(sdCardPath.ToString(), filename);
var stream = new FileStream(filePath, FileMode.Create);

bool compress = bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
stream.Close();

MediaScannerConnection.ScanFile(Application.Context, new String[] { filePath }, null, null);

if (compress)
{
Toast.MakeText((MainActivity)molpayActivity, "Image saved", ToastLength.Short).Show();
}
else
{
Toast.MakeText((MainActivity)molpayActivity, "Image not saved", ToastLength.Short).Show();
}
}

private static String Base64Encode(String plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}

private static String Base64Decode(String base64EncodedData)
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
}
}
77 changes: 77 additions & 0 deletions MOLPayExtensionForIOS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foundation;
using UIKit;
using System.IO;

using MPayXDKExample.iOS;
using MPayXDKExample;

[assembly: Xamarin.Forms.Dependency(typeof(MPExtension))]

namespace MPayXDKExample.iOS
{
public class MPExtension : MOLPayExtension
{
public void SetMOLPayContext(Object mpActivity)
{
// iOS does nothing
}

public String GetAssetPath()
{
return NSBundle.MainBundle.BundlePath;
}

public void saveImageToDevice(String base64ImageString, String filename)
{
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, base64ImageString = {0}", base64ImageString);
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, filename = {0}", filename);

byte[] imageData = System.Convert.FromBase64String(base64ImageString.ToString());
NSData data = NSData.FromArray(imageData);
UIImage img = UIImage.LoadFromData(data);
img.SaveToPhotosAlbum((image, error) =>
{
//var o = image as UIImage;
if (error == null || error.ToString() == "")
{
UIAlertView alert = new UIAlertView()
{
Title = "Info",
Message = "Image saved"
};
alert.AddButton("OK");
alert.Show();
}
else
{
UIAlertView alert = new UIAlertView()
{
Title = "Info",
Message = "Image not saved"
};
alert.AddButton("OK");
alert.Show();
}
});
}

private static String Base64Encode(String plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}

private static String Base64Decode(String base64EncodedData)
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}

}


}
54 changes: 53 additions & 1 deletion MOLPayXDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
using Newtonsoft.Json;
using System.Text;

namespace MOLPayXDK
namespace MPayXDKExample //Update to your project namespace accordingly
{
public interface MOLPayExtension
{
String GetAssetPath();
void saveImageToDevice(String base64ImageString, String filename);
void SetMOLPayContext(Object mpActivity);
}

public class MOLPay : AbsoluteLayout
{
// deploy
Expand All @@ -18,6 +25,7 @@ public class MOLPay : AbsoluteLayout
private const string mptransactionresults = "mptransactionresults://";
private const string mpcloseallwindows = "mpcloseallwindows://";
private const string mprunscriptonpopup = "mprunscriptonpopup://";
private const string mppinstructioncapture = "mppinstructioncapture://";
private const string molpayresulturl = "https://www.onlinepayment.com.my/MOLPay/result.php";
private const string molpaynbepayurl = "https://www.onlinepayment.com.my/MOLPay/nbepay.php";

Expand Down Expand Up @@ -280,6 +288,50 @@ private void OnMainUILoadBegin (object sender, WebNavigatingEventArgs e)
this.molpayUI.Eval(evaljs);
}

else if (url.Contains(mppinstructioncapture))
{
// Must stop loading
e.Cancel = true;

if (isInternalDebugging)
{
System.Diagnostics.Debug.WriteLine("+++++++++++ mppinstructioncapture found");
}

url = url.Replace(mppinstructioncapture, "");

if (Device.OS == TargetPlatform.iOS)
{
url = url.Replace("-", "+");
url = url.Replace("_", "=");
}

string dataString = Base64Decode(url);

if (isInternalDebugging)
{
System.Diagnostics.Debug.WriteLine("+++++++++++ mppinstructioncapture dataString = {0}", dataString);
}

var dataDict = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>> (dataString);

System.Diagnostics.Debug.WriteLine ("+++++++++++ mppinstructioncapture, dataDict = {0}", dataDict);

string base64ImageString;
if (!dataDict.TryGetValue("base64ImageUrlData", out base64ImageString))
{
return;
}

string filename;
if (!dataDict.TryGetValue("filename", out filename))
{
return;
}

DependencyService.Get<MOLPayExtension>().saveImageToDevice(base64ImageString, filename);
}

//var _results = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>> (paymentDetailsJSON);
//
//_MolpayCallback (paymentDetailsJSON);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <meta name="description" content=""> <!-- <meta name="viewport" content="width=device-width"> --> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <meta name="format-detection" content="telephone=no"> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel="stylesheet" href="styles/vendor.34eb91d2.css"> <link rel="stylesheet" href="styles/main.d7816846.css"> </head> <body ng-app="molpayXsdkApp"> <div class="header"> </div> <div id="app-body" class="app-body container-fluid"> <div class="row"> <div class="hidden-xs col-sm-2 col-md-3 col-lg-4"></div> <div class="col-xs-12 col-sm-8 col-md-6 col-lg-4" ng-view=""></div> <div class="hidden-xs col-sm-2 col-md-3 col-lg-4"></div> </div> </div> <div ng-show="isStarting" class="loading text-center vertical-center"> <p>Loading.</p> <p>Please wait.</p> </div> <div class="footer"> </div> <div ng-show="isLoading" class="loading text-center vertical-center"> <div class="loadingbackground"></div> <i class="fa fa-spinner fa-spin fa-3x"></i> <div class="loading-text">Loading...</div> </div> <script src="scripts/vendor.5c22674a.js"></script> <script src="scripts/scripts.5df0fc73.js"></script> </body> </html>
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <meta name="description" content=""> <!-- <meta name="viewport" content="width=device-width"> --> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <meta name="format-detection" content="telephone=no"> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel="stylesheet" href="styles/vendor.34eb91d2.css"> <link rel="stylesheet" href="styles/main.d7e0b867.css"> </head> <body ng-app="molpayXsdkApp"> <div class="header"> </div> <div id="app-body" class="app-body container-fluid"> <div class="row"> <div class="hidden-xs col-sm-2 col-md-3 col-lg-4"></div> <div class="col-xs-12 col-sm-8 col-md-6 col-lg-4" ng-view=""></div> <div class="hidden-xs col-sm-2 col-md-3 col-lg-4"></div> </div> </div> <div ng-show="isStarting" class="loading text-center vertical-center"> <p>Loading.</p> <p>Please wait.</p> </div> <div class="footer"> </div> <div ng-show="isLoading" class="loading text-center vertical-center"> <div class="loadingbackground"></div> <i class="fa fa-spinner fa-spin fa-3x"></i> <div class="loading-text">Loading...</div> </div> <script src="scripts/vendor.f206a627.js"></script> <script src="scripts/scripts.2c26c95c.js"></script> </body> </html>

Large diffs are not rendered by default.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions MPayXDKExample/Droid/MOLPayExtensionForAndroid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Text;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Webkit;
using Android.Widget;
using Android.Util;
using System.IO;
using Android.Media;

using MPayXDKExample.Droid;
using MPayXDKExample;

[assembly: Xamarin.Forms.Dependency(typeof(MPExtension))]

namespace MPayXDKExample.Droid
{
public class MPExtension : MOLPayExtension
{
private static Object molpayActivity;

public void SetMOLPayContext(Object mpActivity)
{
molpayActivity = mpActivity;
}

public String GetAssetPath()
{
return "file:///android_asset/";
}

public void saveImageToDevice(String base64ImageString, String filename)
{
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, base64ImageString = {0}", base64ImageString);
System.Diagnostics.Debug.WriteLine("+++++++++++ saveImageToDevice, filename = {0}", filename);

byte[] imageAsBytes = Base64.Decode(base64ImageString, Base64Flags.Default);
Bitmap bitmap = BitmapFactory.DecodeByteArray(imageAsBytes, 0, imageAsBytes.Length);

var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
var filePath = System.IO.Path.Combine(sdCardPath.ToString(), filename);
var stream = new FileStream(filePath, FileMode.Create);

bool compress = bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
stream.Close();

MediaScannerConnection.ScanFile(Application.Context, new String[] { filePath }, null, null);

if (compress)
{
Toast.MakeText((MainActivity)molpayActivity, "Image saved", ToastLength.Short).Show();
}
else
{
Toast.MakeText((MainActivity)molpayActivity, "Image not saved", ToastLength.Short).Show();
}
}

private static String Base64Encode(String plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}

private static String Base64Decode(String base64EncodedData)
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
}
}
10 changes: 6 additions & 4 deletions MPayXDKExample/Droid/MPayXDKExample.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MOLPayExtensionForAndroid.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
Expand All @@ -109,18 +110,19 @@
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Assets\custom.css" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\index.html" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\fonts\FontAwesome.otf" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\fonts\fontawesome-webfont.eot" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\fonts\fontawesome-webfont.svg" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\fonts\fontawesome-webfont.ttf" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\fonts\fontawesome-webfont.woff" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\fonts\fontawesome-webfont.woff2" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\images\ImageUnavailable.png" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\images\poweredByMOLPay.png" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\scripts\scripts.5df0fc73.js" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\scripts\vendor.5c22674a.js" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\styles\main.d7816846.css" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\scripts\scripts.2c26c95c.js" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\scripts\vendor.f206a627.js" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\styles\main.d7e0b867.css" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\styles\vendor.34eb91d2.css" />
<AndroidAsset Include="Assets\molpay-mobile-xdk-www\index.html" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets" Condition="Exists('..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets')" />
Expand Down
6 changes: 5 additions & 1 deletion MPayXDKExample/Droid/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Xamarin.Forms;
using System.Collections.Generic;

using Android.App;
using Android.Content;
Expand All @@ -22,7 +24,9 @@ protected override void OnCreate(Bundle bundle)

global::Xamarin.Forms.Forms.Init(this, bundle);

LoadApplication(new App("file:///android_asset/"));
LoadApplication(new App());

DependencyService.Get<MOLPayExtension>().SetMOLPayContext(this);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions MPayXDKExample/Droid/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.molpay.mpayxdkexample">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="MPayXDKExample"></application>
</manifest>
Loading

0 comments on commit b406c6b

Please sign in to comment.