Пример #1
0
        public void registerCallForWallets(MobileWallet wallet, WalletCallbackCompletionHandler callback)
        {
            var merchantURL = @"YOUR MERCHANT BACKEND URL HERE";

            NSMutableDictionary jsonDictionary = new NSMutableDictionary();
            NSMutableDictionary amount         = new NSMutableDictionary();
            NSMutableDictionary method         = new NSMutableDictionary();

            amount.SetValueForKey(new NSNumber(1000), new NSString(@"totalAmount"));
            amount.SetValueForKey(new NSNumber(200), new NSString(@"vatAmount"));
            method.SetValueForKey(new NSNumber(0), new NSString(@"fee"));
            switch (wallet)
            {
            case MobileWallet.Vipps:
            {
                amount.SetValueForKey(new NSString(@"NOK"), new NSString(@"currencyCode"));
                method.SetValueForKey(new NSString(@"Vipps"), new NSString(@"id"));
                method.SetValueForKey(new NSString(@"Vipps"), new NSString(@"displayName"));
                jsonDictionary.SetValueForKey(new NSString(@"+471111..."), new NSString(@"phoneNumber"));
                break;
            }

            case MobileWallet.Swish:
            {
                amount.SetValueForKey(new NSString(@"SEK"), new NSString(@"currencyCode"));
                method.SetValueForKey(new NSString(@"SwishM"), new NSString(@"id"));
                method.SetValueForKey(new NSString(@"Swish"), new NSString(@"displayName"));
                break;
            }

            case MobileWallet.MobilePay:
            {
                amount.SetValueForKey(new NSString(@"EUR"), new NSString(@"currencyCode"));
                method.SetValueForKey(new NSString(@"MobilePay"), new NSString(@"id"));
                method.SetValueForKey(new NSString(@"MobilePay"), new NSString(@"displayName"));
                break;
            }

            default: break;
            }

            jsonDictionary.SetValueForKey(amount, new NSString(@"amount"));
            jsonDictionary.SetValueForKey(method, new NSString(@"method"));
            jsonDictionary.SetValueForKey(new NSString(@"000011"), new NSString(@"customerId"));
            jsonDictionary.SetValueForKey(new NSString(@"PiaSDK-iOS-xamarin"), new NSString(@"orderNumber"));
            jsonDictionary.SetValueForKey(new NSNumber(false), new NSString(@"storeCard"));



            jsonDictionary.SetValueForKey(new NSString("YOUR_APP_SCHEME_URL://piasdk"), new NSString(@"redirectUrl"));



            if (NSJsonSerialization.IsValidJSONObject(jsonDictionary))
            {
                NSError             error1   = null;
                NSData              jsonData = NSJsonSerialization.Serialize(jsonDictionary, NSJsonWritingOptions.PrettyPrinted, out error1);
                NSUrl               url      = new NSUrl(merchantURL);
                NSMutableUrlRequest request  = new NSMutableUrlRequest(url, NSUrlRequestCachePolicy.UseProtocolCachePolicy, 30.0);
                request.HttpMethod = @"POST";
                NSMutableDictionary dic = new NSMutableDictionary();
                dic.Add(new NSString("Content-Type"), new NSString("application/json;charset=utf-8;version=2.0"));
                dic.Add(new NSString("Accept"), new NSString("application/json;charset=utf-8;version=2.0"));
                request.Headers = dic;
                request.Body    = jsonData;

                NSError          error2  = null;
                NSUrlSession     session = NSUrlSession.SharedSession;
                NSUrlSessionTask task    = session.CreateDataTask(request, (data, response, error) =>
                {
                    if (data.Length > 0 && error == null)
                    {
                        NSDictionary resultsDictionary = (Foundation.NSDictionary)NSJsonSerialization.Deserialize(data, NSJsonReadingOptions.MutableLeaves, out error2);
                        if (resultsDictionary[@"transactionId"] != null && resultsDictionary[@"walletUrl"] != null)
                        {
                            NSString transactionId = (Foundation.NSString)resultsDictionary[@"transactionId"];
                            NSString walletURL     = (Foundation.NSString)resultsDictionary[@"walletUrl"];
                            transactionInfo        = new NPITransactionInfo(walletURL);
                            callback(WalletRegistrationResponse.SuccessWithWalletURL(NSUrl.FromString(transactionInfo.WalletUrl)));
                        }
                        else
                        {
                            transactionInfo = null;
                            callback(WalletRegistrationResponse.Failure(error));
                        }
                    }
                    else
                    {
                        transactionInfo = null;
                        callback(WalletRegistrationResponse.Failure(error));
                    }
                });

                task.Resume();
            }
        }
Пример #2
0
 public void OnMobileWalletRedirect(MobileWallet p0)
 {
     Toast.MakeText(this, "Redirect was successful. Do a commit call to check status of transaction", ToastLength.Short).Show();
 }
Пример #3
0
 public void OnMobileWalletRedirectInterrupted(MobileWallet p0)
 {
     Toast.MakeText(this, "Process was interrupted. Do a commit call to check status of transaction", ToastLength.Short).Show();
 }
Пример #4
0
 public void OnMobileWalletAppSwitchFailure(MobileWallet p0, MobileWalletError p1)
 {
     Toast.MakeText(this, "Payment failure", ToastLength.Short).Show();
 }