public string Callback()
        {
            Stream req = Request.InputStream;

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

            SwishCheckPaymentRequestStatusResponse resultObject = JsonConvert.DeserializeObject <SwishCheckPaymentRequestStatusResponse>(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");
        }
Esempio n. 2
0
        public JsonResult PaymentStatus(string statusUrl)
        {
            Helpers.VisitorLogHelper.Log();

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

                // Läs in certifikat filen som en byte array, detta är endast för att visa att funktionen nedan kan ta en byte array som skulle kunna hämtats från en databas
                byte[] certDataBytes = System.IO.File.ReadAllBytes(certificatePath);

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

                // Läs in certifikat filen som en byte array, detta är endast för att visa att funktionen nedan kan ta en byte array som skulle kunna hämtats från en databas
                byte[] certDataBytes = System.IO.File.ReadAllBytes(certificatePath);

                // Kontrollera betalnings status med hjälp av certifikatet som en byte array
                result = Helpers.SwishHelper.CheckPaymentRequestStatusWithByteArray(statusUrl, certDataBytes, Config.Production.CertificatePassword);
            }

            // 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));
        }