示例#1
0
        public string Callback()
        {
            Helpers.VisitorLogHelper.Log();

            Stream req = Request.InputStream;

            req.Seek(0, System.IO.SeekOrigin.Begin);
            string json = new StreamReader(req).ReadToEnd();

            logger.Debug("/Test/Callback > json: " + json);

            SwishApi.Models.CheckPaymentRequestStatusResponse resultObject = JsonConvert.DeserializeObject <SwishApi.Models.CheckPaymentRequestStatusResponse>(json);

            switch (resultObject.status)
            {
            case "CREATED":
                // Borde kanske alldrig få CREATED här...
                break;

            case "PAID":
                // Betalningen är klar
                break;

            case "DECLINED":
                // Användaren avbröt betalningen
                break;

            case "ERROR":
                // Något gick fel, om betalningen inte sker inom 3 minuter skickas ERROR
                break;
            }

            // When someone like to use this live i should log this and maybe change the status of some order or somethign to be paid or what the status says.
            // To make a refund you need to save the value of paymentReference
            // var paymentReference = resultObject.paymentReference;


            return("OK");
        }
示例#2
0
        public JsonResult PaymentStatus(string statusUrl)
        {
            Helpers.VisitorLogHelper.Log();

            SwishApi.Models.CheckPaymentRequestStatusResponse result = null;

            // Kontrollera om web.config är satt att vara i test läge
            if (Config.TestMode)
            {
                // Hämta sökvägen till certifikatet
                string certificatePath = HostingEnvironment.MapPath(@"~/App_Data/" + Config.Test.CertificateFileName);

                // Create a SwishApi Client object
                SwishApi.Client client = new SwishApi.Client(certificatePath, Config.Test.CertificatePassword, Config.Test.CallbackURL);

                // Kontrollera betalnings status med hjälp av certifikatet som en byte array
                result = client.CheckPaymentStatus(statusUrl);
            }
            else
            {
                // Hämta sökvägen till certifikatet
                string certificatePath = HostingEnvironment.MapPath(@"~/App_Data/" + Config.Production.CertificateFileName);

                // Create a SwishApi Client object
                SwishApi.Client client = new SwishApi.Client(certificatePath, Config.Production.CertificatePassword, Config.Production.CallbackURL, Config.Production.PayeePaymentReference, Config.Production.PayeeAlias);

                // Kontrollera betalnings status med hjälp av certifikatet som en byte array
                result = client.CheckPaymentStatus(statusUrl);
            }

            // When someone like to use this live i should log this and maybe change the status of some order or somethign to be paid or what the status says.
            // To make a refund you need to save the value of paymentReference
            // var paymentReference = result.paymentReference;

            return(Json(result, JsonRequestBehavior.DenyGet));
        }