Skip to content

Commit 395b514

Browse files
committed
ios update
1 parent 4275ea8 commit 395b514

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

PaystackInline.Forms.Plugin/PaystackInline.Forms.Plugin.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@
100100
</None>
101101
</ItemGroup>
102102

103-
<ItemGroup>
104-
<Folder Include="Droid\Assets\HtmlContent\" />
105-
</ItemGroup>
106-
107103
<!--Additional item groups-->
108104
<!--
109105
<ItemGroup Condition=" $(TargetFramework.StartsWith('Xamarin.TVOS')) ">

PaystackInline.Forms.Plugin/PaystackInline.Forms.Plugin.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>Xam.Plugin.PaystackInline</id>
5-
<version>1.0.0-alpha17</version>
5+
<version>1.0.0-alpha18</version>
66
<title>Paystack Inline Payment for Xamarin and Windows</title>
77
<authors>Akinnagbe Olamide James</authors>
88
<owners>Akinnagbe Olamide James</owners>

PaystackInline.Forms.Plugin/Renderer.ios.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ namespace Plugin.PaystackInline.Forms.Plugin.iOS
1717
{
1818
public class PaystackWebViewRenderer : ViewRenderer<PaystackWebView, WKWebView>, IWKScriptMessageHandler
1919
{
20-
const string JavaScriptFunction = "function invokeCSharpAction(data){window.webkit.messageHandlers.invokeAction.postMessage(data);}";
20+
const string PaymentJavaScriptFunction = "function invokePaymentAction(data){window.webkit.messageHandlers.invokePayAction.postMessage(data);}";
21+
const string ClosePaymentJavaScriptFunction = "function invokeClosePaymentAction(data){window.webkit.messageHandlers.invokeCloseAction.postMessage(data);}";
2122
WKUserContentController userController;
2223

2324
protected override void OnElementChanged(ElementChangedEventArgs<HybridWebView> e)
@@ -26,10 +27,16 @@ protected override void OnElementChanged(ElementChangedEventArgs<HybridWebView>
2627

2728
if (Control == null)
2829
{
30+
var webviewElement = (HybridWebView)Element;
2931
userController = new WKUserContentController();
30-
var script = new WKUserScript(new NSString(JavaScriptFunction), WKUserScriptInjectionTime.AtDocumentEnd, false);
31-
userController.AddUserScript(script);
32-
userController.AddScriptMessageHandler(this, "invokeAction");
32+
var paymentscript = new WKUserScript(new NSString(PaymentJavaScriptFunction), WKUserScriptInjectionTime.AtDocumentEnd, false);
33+
var closeScript = new WKUserScript(new NSString(ClosePaymentJavaScriptFunction), WKUserScriptInjectionTime.AtDocumentEnd, false);
34+
var paystackScript = new WKUserScript(new NSString($"payWithPaystack({webviewElement.Data})"), WKUserScriptInjectionTime.AtDocumentEnd, false);
35+
userController.AddUserScript(paymentscript);
36+
userController.AddUserScript(closeScript);
37+
userController.AddUserScript(paystackScript);
38+
userController.AddScriptMessageHandler(this, "invokePayAction");
39+
userController.AddScriptMessageHandler(this, "invokeCloseAction");
3340

3441
var config = new WKWebViewConfiguration { UserContentController = userController };
3542
var webView = new WKWebView(Frame, config);
@@ -38,7 +45,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<HybridWebView>
3845
if (e.OldElement != null)
3946
{
4047
userController.RemoveAllUserScripts();
41-
userController.RemoveScriptMessageHandler("invokeAction");
48+
userController.RemoveScriptMessageHandler("invokePayAction");
49+
userController.RemoveScriptMessageHandler("invokeCloseAction");
4250
var hybridWebView = e.OldElement as HybridWebView;
4351
hybridWebView.CleanUp();
4452
}
@@ -51,7 +59,16 @@ protected override void OnElementChanged(ElementChangedEventArgs<HybridWebView>
5159

5260
public void DidReceiveScriptMessage(WKUserContentController userContentController, WKScriptMessage message)
5361
{
54-
Element.InvokeCallbackAction(message.Body.ToString());
62+
if (message.Name == "invokePayAction")
63+
{
64+
Element.InvokeCallbackAction(message.Body.ToString());
65+
}
66+
if (message.Name == "invokeCloseAction")
67+
{
68+
Element.InvokeCloseAction();
69+
}
70+
5571
}
72+
5673
}
5774
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<html>
2+
<body>
3+
<form>
4+
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
5+
<script src="https://js.paystack.co/v1/inline.js"></script>
6+
7+
<p>Please Wait...</p>
8+
9+
</form>
10+
11+
<script>
12+
function payWithPaystack(jobj) {
13+
jobj.callback = function (resp) {
14+
invokePaymentAction(resp.reference);
15+
}
16+
jobj.onClose = function () {
17+
invokeClosePaymentAction('');
18+
}
19+
20+
var handler = PaystackPop.setup(jobj);
21+
handler.openIframe();
22+
}
23+
24+
</script>
25+
</body>
26+
</html>

0 commit comments

Comments
 (0)