Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
        public void registerCallForWallets(int wallet, Action completionHandler)
        {
            //#internal_code_section_start
            var merchantURL = new String(@"https://api-gateway-pp.nets.eu/pia/test/merchantdemo/v2/payment/12002835/register");
            //#internal_code_section_end

            /*#external_code_section_start
             * var merchantURL = @"YOUR MERCHANT BACKEND URL HERE";
             #external_code_section_end*/

            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 (int)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"));
                //#internal_code_section_start
                jsonDictionary.SetValueForKey(new NSString(@"+4748059560"), new NSString(@"phoneNumber"));
                //#internal_code_section_end

                /*#external_code_section_start
                 * jsonDictionary.SetValueForKey(new NSString(@"+471111..."), new NSString(@"phoneNumber"));
                 #external_code_section_end*/
                break;
            }

            case (int)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;
            }

            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"));


            //#internal_code_section_start
            jsonDictionary.SetValueForKey(new NSString("eu.nets.pia.xamarin://piasdk"), new NSString(@"redirectUrl"));
            //#internal_code_section_end

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



            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);
                        }
                        else
                        {
                            transactionInfo = null;
                        }
                        completionHandler();
                    }
                    else
                    {
                        transactionInfo = null;
                        completionHandler();
                    }
                });

                task.Resume();
            }
        }
Ejemplo n.º 3
0
        public void registerCardPaymnet(bool payWithPayPal, Action completionHandler)
        {
            var merchantURL = @"YOUR MERCHANT BACKEND URL HERE";

            NSMutableDictionary jsonDictionary = new NSMutableDictionary();

            if (payWithPayPal == false)
            {
                NSMutableDictionary amount = new NSMutableDictionary();
                amount.SetValueForKey(new NSNumber(1000), new NSString(@"totalAmount"));
                amount.SetValueForKey(new NSNumber(0), new NSString(@"vatAmount"));
                amount.SetValueForKey(new NSString(@"EUR"), new NSString(@"currencyCode"));

                jsonDictionary.SetValueForKey(amount, new NSString(@"amount"));
            }
            else
            {
                NSMutableDictionary amount = new NSMutableDictionary();
                amount.SetValueForKey(new NSNumber(1000), new NSString(@"totalAmount"));
                amount.SetValueForKey(new NSNumber(0), new NSString(@"vatAmount"));
                amount.SetValueForKey(new NSString(@"DKK"), new NSString(@"currencyCode"));

                jsonDictionary.SetValueForKey(amount, new NSString(@"amount"));
            }

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

            if (payWithPayPal)
            {
                NSMutableDictionary method = new NSMutableDictionary();
                method.SetValueForKey(new NSString(@"PayPal"), new NSString(@"id"));
                method.SetValueForKey(new NSString(@"PayPal"), new NSString(@"displayName"));
                method.SetValueForKey(new NSNumber(0), new NSString(@"fee"));
                jsonDictionary.SetValueForKey(method, new NSString(@"method"));
            }

            if (isPayingWithToken)
            {
                isPayingWithToken = false;
                // Make sure you have a saved card in your backend.
                NSMutableDictionary method = new NSMutableDictionary();
                method.SetValueForKey(new NSString(@"EasyPayment"), new NSString(@"id"));
                method.SetValueForKey(new NSString(@"Easy Payment"), new NSString(@"displayName"));
                method.SetValueForKey(new NSNumber(0), new NSString(@"fee"));
                jsonDictionary.SetValueForKey(method, new NSString(@"method"));
                jsonDictionary.SetValueForKey(new NSString(@"492500******0004"), new NSString(@"cardId"));
            }

            if (isPaytrail)
            {
                isPaytrail = false;
                NSMutableDictionary method = new NSMutableDictionary();
                method.SetValueForKey(new NSString(@"PaytrailNordea"), new NSString(@"id"));
                jsonDictionary.SetValueForKey(method, new NSString(@"method"));

                // dummy customer details
                jsonDictionary.SetValueForKey(new NSString(getPaytrailOrderNumber()), new NSString(@"orderNumber"));
                jsonDictionary.SetValueForKey(new NSString(@"*****@*****.**"), new NSString(@"customerEmail"));
                jsonDictionary.SetValueForKey(new NSString(@"Bill"), new NSString(@"customerFirstName"));
                jsonDictionary.SetValueForKey(new NSString(@"Buyer"), new NSString(@"customerLastName"));
                jsonDictionary.SetValueForKey(new NSString(@"Testaddress"), new NSString(@"customerAddress1"));
                jsonDictionary.SetValueForKey(new NSString(@"00510"), new NSString(@"customerPostCode"));
                jsonDictionary.SetValueForKey(new NSString(@"Helsinki"), new NSString(@"customerTown"));
                jsonDictionary.SetValueForKey(new NSString(@"FI"), new NSString(@"customerCountry"));
                jsonDictionary.Remove(new NSString(@"storeCard"));
            }

            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[@"redirectOK"] != null)
                        {
                            NSString transactionId = (Foundation.NSString)resultsDictionary[@"transactionId"];
                            NSString redirectOK    = (Foundation.NSString)resultsDictionary[@"redirectOK"];
                            transactionInfo        = new NPITransactionInfo(transactionId, redirectOK);
                            completionHandler();
                        }
                        else
                        {
                            transactionInfo   = null;
                            registrationError = error;
                            completionHandler();
                        }
                    }
                    else
                    {
                        transactionInfo   = null;
                        registrationError = error;
                        completionHandler();
                    }
                });

                task.Resume();
            }
        }
Ejemplo n.º 4
0
        public void getTransactionInfo(bool payWithPayPal, Action completionHandler)
        {
            //#internal_code_section_start
            var merchantURL = new String(@"");

            if (payWithPayPal)
            {
                merchantURL = @"https://api-gateway-pp.nets.eu/pia/merchantdemo/v2/payment/493809/register";
            }
            else
            {
                merchantURL = @"https://api-gateway-pp.nets.eu/pia/test/merchantdemo/v2/payment/12002835/register";
            }

            //#internal_code_section_end

            /*#external_code_section_start
             * var merchantURL = @"YOUR MERCHANT BACKEND URL HERE";
             #external_code_section_end*/

            NSMutableDictionary jsonDictionary = new NSMutableDictionary();

            if (payWithPayPal == false)
            {
                NSMutableDictionary amount = new NSMutableDictionary();
                amount.SetValueForKey(new NSNumber(1000), new NSString(@"totalAmount"));
                amount.SetValueForKey(new NSNumber(200), new NSString(@"vatAmount"));
                amount.SetValueForKey(new NSString(@"EUR"), new NSString(@"currencyCode"));

                jsonDictionary.SetValueForKey(amount, new NSString(@"amount"));
            }
            else
            {
                NSMutableDictionary amount = new NSMutableDictionary();
                amount.SetValueForKey(new NSNumber(1000), new NSString(@"totalAmount"));
                amount.SetValueForKey(new NSNumber(0), new NSString(@"vatAmount"));
                amount.SetValueForKey(new NSString(@"DKK"), new NSString(@"currencyCode"));

                jsonDictionary.SetValueForKey(amount, new NSString(@"amount"));
            }

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

            if (payWithPayPal)
            {
                NSMutableDictionary method = new NSMutableDictionary();
                method.SetValueForKey(new NSString(@"PayPal"), new NSString(@"id"));
                method.SetValueForKey(new NSString(@"PayPal"), new NSString(@"displayName"));
                method.SetValueForKey(new NSNumber(0), new NSString(@"fee"));
                jsonDictionary.SetValueForKey(method, new NSString(@"method"));
            }

            if (isPayingWithToken)
            {
                // Make sure you have a saved card in your backend.
                NSMutableDictionary method = new NSMutableDictionary();
                method.SetValueForKey(new NSString(@"EasyPayment"), new NSString(@"id"));
                method.SetValueForKey(new NSString(@"Easy Payment"), new NSString(@"displayName"));
                method.SetValueForKey(new NSNumber(0), new NSString(@"fee"));
                jsonDictionary.SetValueForKey(method, new NSString(@"method"));
                jsonDictionary.SetValueForKey(new NSString(@"492500******0004"), new NSString(@"cardId"));
            }

            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[@"redirectOK"] != null)
                        {
                            NSString transactionId = (Foundation.NSString)resultsDictionary[@"transactionId"];
                            NSString redirectOK    = (Foundation.NSString)resultsDictionary[@"redirectOK"];
                            transactionInfo        = new NPITransactionInfo(transactionId, redirectOK);
                        }
                        else
                        {
                            transactionInfo = null;
                        }
                        completionHandler();
                    }
                    else
                    {
                        transactionInfo = null;
                        completionHandler();
                    }
                });

                task.Resume();
            }
        }