Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 12 additions & 6 deletions PaystackInline.Forms.Plugin/Paystack.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,24 @@ public void CleanUp()
/// <param name="data"></param>
public void InvokeCallbackAction(string data)
{
if (action == null || data == null)
if (action != null)
{
return;
action.Invoke(data);
}
action.Invoke(data);

PaymentSuccessful?.Invoke(this, data);
}
public void InvokeCloseAction()
{
if (closeAction == null)
return;
closeAction.Invoke();
if (closeAction != null)
{
closeAction.Invoke();
}
PaymentClosed?.Invoke(this, "");
}

public event EventHandler<string> PaymentClosed;
public event EventHandler<string> PaymentSuccessful;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<!--Work around so the conditions work below-->
<TargetFrameworks></TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid81;uap10.0.16299</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid81</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid81</TargetFrameworks>
<!--<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid80;uap10.0.16299</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid80</TargetFrameworks>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<package >
<metadata minClientVersion="3.3">
<id>Xam.Plugin.PaystackInline</id>
<version>2.0.0</version>
<version>2.0.2.1</version>
<title>Paystack Inline Payment for Xamarin and Windows</title>
<authors>Akinnagbe Olamide James</authors>
<owners>Akinnagbe Olamide James</owners>
<licenseUrl>https://opensource.org/licenses/MS-PL</licenseUrl>
<projectUrl>https://github.com/Akinnagbe/PaystackInlinePayment</projectUrl>
<projectUrl>https://github.com/Akinnagbe/PaystackInline.Forms.Plugin</projectUrl>
<iconUrl>https://paystack.com/favicon.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Xamarin and Window Plugin to make payment with Debit Card using Paystack Inline</description>
Expand All @@ -34,8 +34,8 @@
<file src="bin\Release\netstandard2.0\Plugin.PaystackInline.Forms.Plugin.*pdb" target="lib\netstandard2.0" />

<!-- Android reference assemblies -->
<file src="bin\Release\monoandroid81\81\Plugin.PaystackInline.Forms.Plugin.dll" target="lib\MonoAndroid80" />
<file src="bin\Release\monoandroid81\81\Plugin.PaystackInline.Forms.Plugin.*pdb" target="lib\MonoAndroid80" />
<file src="bin\Release\monoandroid81\81\Plugin.PaystackInline.Forms.Plugin.dll" target="lib\MonoAndroid81" />
<file src="bin\Release\monoandroid81\81\Plugin.PaystackInline.Forms.Plugin.*pdb" target="lib\MonoAndroid8" />
<!--<file src="bin\Release\MonoAndroid10\Plugin.PaystackInline.Forms.Plugin.dll" target="lib\MonoAndroid10" />
<file src="bin\Release\MonoAndroid10\Plugin.PaystackInline.Forms.Plugin.*pdb" target="lib\MonoAndroid10" />-->

Expand Down
19 changes: 11 additions & 8 deletions PaystackInline.Forms.Plugin/Renderer.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ namespace Plugin.PaystackInline.Forms.Plugin.Droid
[Preserve(AllMembers = true)]
public class PaystackWebViewRenderer : ViewRenderer<PaystackWebView, Android.Webkit.WebView>
{
private const string CallBackJavaScriptFunction = "function invokeCSharpAction(data){jsBridge.invokeCallbackAction(data);}";
private const string CloseJavaScriptFunction = "function invokeCSharpCloseAction(){jsBridge.invokeCloseAction();}";

private Context _context;

public PaystackWebViewRenderer(Context context) : base(context)
Expand Down Expand Up @@ -45,13 +44,12 @@ protected override void OnElementChanged(ElementChangedEventArgs<PaystackWebView
{
//subscribe to Events
var webviewElement = Element;
Control.AddJavascriptInterface(new JSBridge(this, _context), "jsBridge");
Control.AddJavascriptInterface(new JSBridge(this), "jsBridge");
string content = LoadHtmlString();
Control.SetWebViewClient(new CustomWebViewClient(webviewElement.Data));

Control.LoadDataWithBaseURL("", content, "text/html", "UTF-8", null);
InjectJS(CallBackJavaScriptFunction);
InjectJS(CloseJavaScriptFunction);

}
}

Expand Down Expand Up @@ -118,6 +116,8 @@ internal class CustomWebViewClient : WebViewClient
{
private string Record = "";
private const string logTag = "Plugin.PaystackInline.Forms";
private const string CallBackJavaScriptFunction = "function invokeCSharpAction(data){jsBridge.invokeCallbackAction(data);}";
private const string CloseJavaScriptFunction = "function invokeCSharpCloseAction(){jsBridge.invokeCloseAction();}";
public CustomWebViewClient(string record)
{
Record = record;
Expand All @@ -127,7 +127,10 @@ public override void OnPageFinished(Android.Webkit.WebView view, string url)
{
base.OnPageFinished(view, url);

view.EvaluateJavascript(CloseJavaScriptFunction, null);
view.EvaluateJavascript(CallBackJavaScriptFunction, null);
view.LoadUrl(string.Format("javascript:payWithPaystack({0})", Record));

Android.Util.Log.Info(logTag, $"OnPageFinished: {url}");
}
public override void OnPageStarted(Android.Webkit.WebView view, string url, Bitmap favicon)
Expand Down Expand Up @@ -156,11 +159,11 @@ public override void OnReceivedHttpError(Android.Webkit.WebView view, IWebResour
internal class JSBridge : Java.Lang.Object
{
private readonly WeakReference<PaystackWebViewRenderer> hybridWebViewRenderer;
private readonly Context _context;
public JSBridge(PaystackWebViewRenderer hybridRenderer, Context context)

public JSBridge(PaystackWebViewRenderer hybridRenderer)
{
hybridWebViewRenderer = new WeakReference<PaystackWebViewRenderer>(hybridRenderer);
_context = context;

}

[JavascriptInterface]
Expand Down
Loading