Exemple #1
0
        static void Main(string[] args)
        {
            var   client = new Scanpay.Client("1153:YHZIUGQw6NkCIYa3mG6CWcgShnl13xuI7ODFUYuMy0j790Q6ThwBEjxfWFXwJZ0W");
            ulong trnid  = 522;
            var   data   = new Scanpay.CaptureReq
            {
                total = "1 DKK",
                index = 0,
            };
            /* The following opts is to use the test environment, omit it to use the production env. */
            var opts = new Scanpay.Options
            {
                hostname = "api.test.scanpay.dk",
            };

            try
            {
                client.capture(trnid, data, opts);
            }
            catch (Exception e)
            {
                Console.WriteLine("Capture failed: " + e.Message);
                return;
            }
            Console.WriteLine("Capture of {0} succeded", data.total);
        }
        static void Main(string[] args)
        {
            var client = new Scanpay.Client("1153:YHZIUGQw6NkCIYa3mG6CWcgShnl13xuI7ODFUYuMy0j790Q6ThwBEjxfWFXwJZ0W");
            var data   = new Scanpay.NewURLReq
            {
                orderid    = "suborder912",
                successurl = "https://example.com",
                subscriber = new Scanpay.Subscriber
                {
                    @ref = "sub1234",
                },
                billing = new Scanpay.Billing
                {
                    name    = "Hans Jensen",
                    company = "HJ Planteskole ApS",
                    vatin   = "DK12345678",
                    gln     = "",
                    email   = "*****@*****.**",
                    phone   = "+45 12345678",
                    address = new string[]
                    {
                        "Grønnegade 5, st. th",
                        "C/O Hans Jensen",
                    },
                    city    = "Børum",
                    zip     = "1234",
                    country = "DK",
                },
                shipping = new Scanpay.Shipping
                {
                    name    = "John Hanson",
                    company = "HJ Planteskole ApS",
                    email   = "*****@*****.**",
                    phone   = "+45 12345679",
                    address = new string[]
                    {
                        "Gryngade 90",
                        "C/O John Hanson",
                    },
                    city    = "Ørum",
                    zip     = "1235",
                    country = "DK",
                },
                language = "",
                lifetime = "1h",
            };
            /* The following opts is to use the test environment, omit it to use the production env. */
            var opts = new Scanpay.Options
            {
                hostname = "api.test.scanpay.dk",
            };
            var url = client.newURL(data, opts);

            Console.WriteLine("Subscription URL is: " + url);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var   client       = new Scanpay.Client("1153:YHZIUGQw6NkCIYa3mG6CWcgShnl13xuI7ODFUYuMy0j790Q6ThwBEjxfWFXwJZ0W");
            ulong subscriberid = 5;
            var   data         = new Scanpay.RenewReq
            {
                successurl = "https://docs.test.scanpay.dk/subscriptions/renew-subscriber",
                language   = "da",
                lifetime   = "1h",
            };
            /* The following opts is to use the test environment, omit it to use the production env. */
            var opts = new Scanpay.Options
            {
                hostname = "api.test.scanpay.dk",
            };
            var url = client.renew(subscriberid, data, opts);

            Console.WriteLine("Subscriber renew URL is: " + url);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            var client = new Scanpay.Client("1089:bx2a4DATi8ad87Nm4uaxg5nggYA8J/Hv99CON977YiEdvYa6DmMwdoRPoYWyBJSi");
            var opts   = new Scanpay.Options {
                hostname = "api.test.scanpay.dk"
            };
            var seqRes = client.seq(0, opts);

            Console.WriteLine("Printing seq res: (" + seqRes.seq + ")");
            Console.WriteLine("Changes: (" + seqRes.changes.Length + ")");

            foreach (var change in seqRes.changes)
            {
                Console.WriteLine("Change (transaction id=" + change.id + ")");
                if (change.error != null)
                {
                    Console.WriteLine("  error = " + change.error);
                    continue;
                }
                Console.WriteLine("  rev        = " + change.rev);
                Console.WriteLine("  orderid    = " + change.orderid);
                Console.WriteLine("  payid time = " + change.time.created);
                Console.WriteLine("  auth time  = " + change.time.authorized);
                Console.WriteLine("  authorized = " + change.totals.authorized);
                Console.WriteLine("  captured   = " + change.totals.captured);
                Console.WriteLine("  refunded   = " + change.totals.refunded);
                Console.WriteLine("  left capt. = " + change.totals.left);
                Console.WriteLine("  acts(" + change.acts.Length + ")");
                var nact = 0;
                foreach (var act in change.acts)
                {
                    Console.WriteLine("    " + (nact++) + ":");
                    Console.WriteLine("    name = " + act.act);
                    Console.WriteLine("    time = " + act.time);
                    Console.WriteLine("    total= " + act.total);
                }
            }
            Console.WriteLine("New seq after applying all changes: seq = " + seqRes.seq);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            var   client       = new Scanpay.Client("1153:YHZIUGQw6NkCIYa3mG6CWcgShnl13xuI7ODFUYuMy0j790Q6ThwBEjxfWFXwJZ0W");
            ulong subscriberid = 5;
            var   data         = new Scanpay.ChargeReq
            {
                orderid = "999",
                items   = new Scanpay.Item[]
                {
                    new Scanpay.Item
                    {
                        name     = "Ultra Bike 7000",
                        total    = "1337.01 DKK",
                        quantity = 2,
                        sku      = "ff123",
                    },
                    new Scanpay.Item
                    {
                        name     = "巨人宏偉的帽子",
                        total    = "420 DKK",
                        quantity = 2,
                        sku      = "124",
                    },
                },
                autocapture = true,
            };
            /* The following opts is to use the test environment, omit it to use the production env. */
            var opts = new Scanpay.Options
            {
                hostname = "api.test.scanpay.dk",
                headers  = new Dictionary <string, string>
                {
                    ["Idempotency-Key"] = client.generateIdempotencyKey(),
                },
            };

            Scanpay.ChargeRes res = null;
            int i;

            for (i = 0; i < 3; i++)
            {
                Console.WriteLine("Attempting charge with idempotency key " + opts.headers["Idempotency-Key"]);
                try
                {
                    res = client.charge(subscriberid, data, opts);
                    break;
                }
                catch (Scanpay.IdempotentResponseException e)
                {
                    /* Regenerate idempotency key */
                    opts.headers["Idempotency-Key"] = client.generateIdempotencyKey();
                    Console.WriteLine("Idempotent exception: " + e.Message);
                    if (i < 2)
                    {
                        Console.WriteLine("Regenerating idempotency key");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception (not idempotent): " + e.Message);
                }
                System.Threading.Thread.Sleep(50);
            }
            if (i == 3)
            {
                throw new Exception("Attempted charging 3 times and failed");
            }
            Console.WriteLine("Charge succeded:");
            Console.WriteLine("id = {0}", res.id);
            Console.WriteLine("authorized = {0}", res.totals.authorized);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            var client = new Scanpay.Client("1153:YHZIUGQw6NkCIYa3mG6CWcgShnl13xuI7ODFUYuMy0j790Q6ThwBEjxfWFXwJZ0W");
            var data   = new Scanpay.NewURLReq
            {
                orderid    = "999",
                successurl = "https://example.com",
                items      = new Scanpay.Item[]
                {
                    new Scanpay.Item
                    {
                        name     = "Ultra Bike 7000",
                        total    = "1337.01 DKK",
                        quantity = 2,
                        sku      = "ff123",
                    },
                    new Scanpay.Item
                    {
                        name     = "巨人宏偉的帽子",
                        total    = "420 DKK",
                        quantity = 2,
                        sku      = "124",
                    },
                },
                billing = new Scanpay.Billing
                {
                    name    = "Hans Jensen",
                    company = "HJ Planteskole ApS",
                    vatin   = "DK12345678",
                    gln     = "",
                    email   = "*****@*****.**",
                    phone   = "+45 12345678",
                    address = new string[]
                    {
                        "Grønnegade 5, st. th",
                        "C/O Hans Jensen",
                    },
                    city    = "Børum",
                    zip     = "1234",
                    country = "DK",
                },
                shipping = new Scanpay.Shipping
                {
                    name    = "John Hanson",
                    company = "HJ Planteskole ApS",
                    email   = "*****@*****.**",
                    phone   = "+45 12345679",
                    address = new string[]
                    {
                        "Gryngade 90",
                        "C/O John Hanson",
                    },
                    city    = "Ørum",
                    zip     = "1235",
                    country = "DK",
                },
                language    = "",
                autocapture = false,
                lifetime    = "1h",
            };
            /* The following opts is to use the test environment, omit it to use the production env. */
            var opts = new Scanpay.Options
            {
                hostname = "api.test.scanpay.dk",
            };
            var url = client.newURL(data, opts);

            Console.WriteLine("Payment URL is: " + url);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var client = new Scanpay.Client("1089:bx2a4DATi8ad87Nm4uaxg5nggYA8J/Hv99CON977YiEdvYa6DmMwdoRPoYWyBJSi");
            var data   = new Scanpay.NewURLReq
            {
                orderid    = "999",
                successurl = "https://example.com",
                items      = new Scanpay.Item[]
                {
                    new Scanpay.Item
                    {
                        name     = "Ultra Bike 7000",
                        price    = "1337.01 DKK",
                        quantity = 2,
                        sku      = "ff123",
                    },
                    new Scanpay.Item
                    {
                        name     = "巨人宏偉的帽子",
                        price    = "420 DKK",
                        quantity = 2,
                        sku      = "124",
                    },
                },
                billing = new Scanpay.Billing
                {
                    name    = "Hans Jensen",
                    company = "HJ Planteskole ApS",
                    vatin   = "DK12345678",
                    gln     = "",
                    email   = "*****@*****.**",
                    phone   = "+45 12345678",
                    address = new string[]
                    {
                        "Grønnegade 5, st. th",
                        "C/O Hans Jensen",
                    },
                    city    = "Børum",
                    zip     = "1234",
                    country = "DK",
                },
                shipping = new Scanpay.Shipping
                {
                    name    = "John Hanson",
                    company = "HJ Planteskole ApS",
                    email   = "*****@*****.**",
                    phone   = "+45 12345679",
                    address = new string[]
                    {
                        "Gryngade 90",
                        "C/O John Hanson",
                    },
                    city    = "Ørum",
                    zip     = "1235",
                    country = "DK",
                },
                language    = "",
                autocapture = false,
                lifetime    = "1h",
            };
            /* The following opts is to use the test environment, omit it to use the production env. */
            var opts = new Scanpay.Options
            {
                hostname = "api.test.scanpay.dk",
            };
            var url = client.newURL(data, opts);

            Console.WriteLine("Payment URL is: " + url);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            var client = new Scanpay.Client("1153:YHZIUGQw6NkCIYa3mG6CWcgShnl13xuI7ODFUYuMy0j790Q6ThwBEjxfWFXwJZ0W");
            var opts   = new Scanpay.Options {
                hostname = "api.test.scanpay.dk"
            };
            var seqRes = client.seq(360, opts);

            Console.WriteLine("Printing seq res: (" + seqRes.seq + ")");
            Console.WriteLine("Changes: (" + seqRes.changes.Length + ")");

            foreach (var change in seqRes.changes)
            {
                if (change.error != null)
                {
                    Console.WriteLine("  error = " + change.error);
                    continue;
                }
                if (change is Scanpay.TransactionChange)
                {
                    var trn = (Scanpay.TransactionChange)change;
                    Console.WriteLine("Change (transaction id=" + trn.id + ")");
                    Console.WriteLine("  rev        = " + trn.rev);
                    Console.WriteLine("  orderid    = " + trn.orderid);
                    if (trn is Scanpay.ChargeChange)
                    {
                        var charge = (Scanpay.ChargeChange)trn;
                        Console.WriteLine("  subscriber id = " + charge.subscriber.id);
                        Console.WriteLine("  subscriber ref = " + charge.subscriber.@ref);
                    }
                    Console.WriteLine("  payid time = " + trn.time.created);
                    Console.WriteLine("  auth time  = " + trn.time.authorized);
                    Console.WriteLine("  authorized = " + trn.totals.authorized);
                    Console.WriteLine("  captured   = " + trn.totals.captured);
                    Console.WriteLine("  refunded   = " + trn.totals.refunded);
                    Console.WriteLine("  left capt. = " + trn.totals.left);
                    Console.WriteLine("  acts(" + trn.acts.Length + ")");
                    var nact = 0;
                    foreach (var act in trn.acts)
                    {
                        Console.WriteLine("    " + (nact++) + ":");
                        Console.WriteLine("    name = " + act.act);
                        Console.WriteLine("    time = " + act.time);
                        Console.WriteLine("    total= " + act.total);
                    }
                }
                else if (change is Scanpay.SubscriberChange)
                {
                    var sub = (Scanpay.SubscriberChange)change;
                    Console.WriteLine("Change (subscriber id=" + sub.id + ")");
                    Console.WriteLine("  rev        = " + sub.rev);
                    Console.WriteLine("  ref    = " + sub.@ref);
                    Console.WriteLine("  orderid    = " + sub.orderid);
                    Console.WriteLine("  payid time = " + sub.time.created);
                    Console.WriteLine("  auth time  = " + sub.time.authorized);
                    Console.WriteLine("  acts(" + sub.acts.Length + ")");
                    var nact = 0;
                    foreach (var act in sub.acts)
                    {
                        Console.WriteLine("    " + (nact++) + ":");
                        Console.WriteLine("    name = " + act.act);
                        Console.WriteLine("    time = " + act.time);
                        Console.WriteLine("    total= " + act.total);
                    }
                }
                else
                {
                    Console.WriteLine("unknown change type");
                }
            }
            Console.WriteLine("New seq after applying all changes: seq = " + seqRes.seq);
        }