Esempio n. 1
0
        //[TestCase(typeof(Przelewy24PaymentRequest), PaymentMethod.Przelewy24, typeof(PaymentResponse))] // Payment option is not enabled in website profile
        public async Task CanCreateSpecificPaymentType(Type paymentType, PaymentMethods?paymentMethod, Type expectedResponseType)
        {
            // If: we create a specific payment type with some bank transfer specific values
            PaymentRequest paymentRequest = (PaymentRequest)Activator.CreateInstance(paymentType);

            paymentRequest.Amount      = new Amount(Currency.EUR, "100.00");
            paymentRequest.Description = "Description";
            paymentRequest.RedirectUrl = DefaultRedirectUrl;
            paymentRequest.Method      = paymentMethod;

            // Set required billing email for Przelewy24
            if (paymentRequest is Przelewy24PaymentRequest request)
            {
                request.BillingEmail = "*****@*****.**";
            }

            // When: We send the payment request to Mollie
            PaymentResponse result = await PaymentClient.CreatePaymentAsync(paymentRequest);

            // Then: Make sure all requested parameters match the response parameter values
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedResponseType, result.GetType());
            Assert.AreEqual(paymentRequest.Amount.Currency, result.Amount.Currency);
            Assert.AreEqual(paymentRequest.Amount.Value, result.Amount.Value);
            Assert.AreEqual(paymentRequest.Description, result.Description);
            Assert.AreEqual(paymentRequest.RedirectUrl, result.RedirectUrl);
        }
        public async Task <PaymentResponse> CreatePayment(int bookingId, double amount, string locale)
        {
            var booking = _bookingPaymentRepository.GetBookingPayment(bookingId);

            if (booking == null)
            {
                booking = _bookingPaymentRepository.AddBookingPayment(new BookingPayment {
                    BookingId = bookingId, Amount = amount
                });
            }

            var molliePaymentResponse = await _paymentClient.CreatePaymentAsync(
                new PaymentRequest
            {
                Amount      = new Amount(Currency.EUR, amount.ToString("F02", CultureInfo.InvariantCulture)),
                Description = $"Payment for booking {bookingId}",
                RedirectUrl = $"{_mollieOptions.RedirectUrl}/{bookingId}",
                WebhookUrl  = _mollieOptions.WebhookUrl,
                Metadata    = bookingId.ToString()
            });

            booking.TransactionId = molliePaymentResponse.Id;

            _bookingPaymentRepository.UpdateBookingPayment(booking);

            return(molliePaymentResponse);
        }
Esempio n. 3
0
        public async Task CanCreatePaymentWithCustomMetaDataClass()
        {
            // If: We create a payment with meta data
            CustomMetadataClass metadataRequest = new CustomMetadataClass()
            {
                OrderId     = 1,
                Description = "Custom description"
            };

            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = DefaultRedirectUrl,
            };

            paymentRequest.SetMetadata(metadataRequest);

            // When: We send the payment request to Mollie
            PaymentResponse result = await PaymentClient.CreatePaymentAsync(paymentRequest);

            CustomMetadataClass metadataResponse = result.GetMetadata <CustomMetadataClass>();

            // Then: Make sure we get the same json result as metadata
            Assert.IsNotNull(metadataResponse);
            Assert.AreEqual(metadataRequest.OrderId, metadataResponse.OrderId);
            Assert.AreEqual(metadataRequest.Description, metadataResponse.Description);
        }
        public async Task CreatePaymentAsync_PaymentWithSinglePaymentMethod_RequestIsSerializedInExpectedFormat()
        {
            // Given: We create a payment request with a single payment method
            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = "http://www.mollie.com",
                Method      = PaymentMethod.Ideal
            };
            string        expectedPaymentMethodJson = $"\"method\":[\"{PaymentMethod.Ideal}\"";
            const string  jsonResponse  = @"{
                ""amount"":{
                    ""currency"":""EUR"",
                    ""value"":""100.00""
                },
                ""description"":""Description"",
                ""method"":""ideal"",
                ""redirectUrl"":""http://www.mollie.com""}";
            var           mockHttp      = this.CreateMockHttpMessageHandler(HttpMethod.Post, $"{BaseMollieClient.ApiEndPoint}payments", jsonResponse, expectedPaymentMethodJson);
            HttpClient    httpClient    = mockHttp.ToHttpClient();
            PaymentClient paymentClient = new PaymentClient("abcde", httpClient);

            // When: We send the request
            PaymentResponse paymentResponse = await paymentClient.CreatePaymentAsync(paymentRequest);

            // Then
            mockHttp.VerifyNoOutstandingExpectation();
            this.AssertPaymentIsEqual(paymentRequest, paymentResponse);
            Assert.AreEqual(paymentRequest.Method, paymentResponse.Method);
        }
Esempio n. 5
0
        public async Task CanCreateDefaultPaymentWithAllFields()
        {
            // If: we create a payment request where all parameters have a value
            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = DefaultRedirectUrl,
                Locale      = Locale.nl_NL,
                Metadata    = "{\"firstName\":\"John\",\"lastName\":\"Doe\"}",
                Method      = PaymentMethods.BankTransfer,
                WebhookUrl  = DefaultWebhookUrl
            };

            // When: We send the payment request to Mollie
            PaymentResponse result = await PaymentClient.CreatePaymentAsync(paymentRequest);

            // Then: Make sure all requested parameters match the response parameter values
            Assert.IsNotNull(result);
            Assert.AreEqual(paymentRequest.Amount.Currency, result.Amount.Currency);
            Assert.AreEqual(paymentRequest.Amount.Value, result.Amount.Value);
            Assert.AreEqual(paymentRequest.Description, result.Description);
            Assert.AreEqual(paymentRequest.RedirectUrl, result.RedirectUrl);
            Assert.AreEqual(paymentRequest.Locale, result.Locale);
            Assert.AreEqual(paymentRequest.Metadata, result.Metadata);
            Assert.AreEqual(paymentRequest.WebhookUrl, result.WebhookUrl);
        }
Esempio n. 6
0
        private async Task <PaymentResponse> CreatePayment(string amount = "100.00")
        {
            PaymentRequest paymentRequest = new CreditCardPaymentRequest
            {
                Amount      = new Amount(Currency.EUR, amount),
                Description = "Description",
                RedirectUrl = DefaultRedirectUrl
            };

            return(await PaymentClient.CreatePaymentAsync(paymentRequest));
        }
Esempio n. 7
0
        static void OutputNewPayment(PaymentClient paymentClient)
        {
            Console.WriteLine("Creating a payment");
            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount      = 100,
                Description = "Test payment of the example project",
                RedirectUrl = "http://google.com"
            };

            PaymentResponse paymentResponse = paymentClient.CreatePaymentAsync(paymentRequest).Result;

            Console.WriteLine("Payment created");
            Console.WriteLine("");
            Console.WriteLine($"Payment can be paid on the following URL: {paymentResponse.Links.PaymentUrl}");
        }
Esempio n. 8
0
        public async Task WhenRetrievingAListOfPaymentsPaymentSubclassesShouldBeInitialized()
        {
            // Given: We create a new payment
            IdealPaymentRequest paymentRequest = new IdealPaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = DefaultRedirectUrl
            };
            await PaymentClient.CreatePaymentAsync(paymentRequest);

            // When: We retrieve it in a list
            ListResponse <PaymentResponse> result = await PaymentClient.GetPaymentListAsync(null, 5);

            // Then: We expect a list with a single ideal payment
            Assert.IsInstanceOfType(result.Items.First(), typeof(IdealPaymentResponse));
        }
Esempio n. 9
0
        public async Task <BackerPaymentRequestModel> Handle(CheckoutBackerCommand request, CancellationToken cancellationToken)
        {
            var molliePaymentClient = new PaymentClient(_applicationSettings.PaymentProviderApiKey);
            var paymentResponse     = await molliePaymentClient.CreatePaymentAsync(new PaymentRequest
            {
                Description = request.Description,
                Amount      = new Amount(request.Currency, request.TotalAmount),
                RedirectUrl = request.RedirectUrl,
                Locale      = request.Locale,
                WebhookUrl  = "https://google.be"
            }, true);

            return(new BackerPaymentRequestModel
            {
                CheckoutUrl = paymentResponse.Links.Checkout.Href
            });
        }
        public async Task CanCreatePaymentWithMetaData()
        {
            // If: We create a payment with meta data
            var metadata       = "this is my metadata";
            var paymentRequest = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = DefaultRedirectUrl,
                Metadata    = metadata
            };

            // When: We send the payment request to Mollie
            var result = await PaymentClient.CreatePaymentAsync(paymentRequest);

            // Then: Make sure we get the same json result as metadata
            Assert.Equal(metadata, result.Metadata);
        }
Esempio n. 11
0
        public async Task CanCreatePaymentWithJsonMetaData()
        {
            // If: We create a payment with meta data
            string         json           = "{\"order_id\":\"4.40\"}";
            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = DefaultRedirectUrl,
                Metadata    = json
            };

            // When: We send the payment request to Mollie
            PaymentResponse result = await PaymentClient.CreatePaymentAsync(paymentRequest);

            // Then: Make sure we get the same json result as metadata
            Assert.AreEqual(json, result.Metadata);
        }
Esempio n. 12
0
        public async Task CreatePaymentAsync_IncludeQrCode_QueryStringContainsIncludeQrCodeParameter()
        {
            // Given: We make a request to create a payment and include the QR code
            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = "http://www.mollie.com",
                Method      = PaymentMethod.Ideal
            };
            var           mockHttp      = this.CreateMockHttpMessageHandler(HttpMethod.Post, $"{BaseMollieClient.ApiEndPoint}payments?include=details.qrCode", defaultPaymentJsonResponse);
            HttpClient    httpClient    = mockHttp.ToHttpClient();
            PaymentClient paymentClient = new PaymentClient("abcde", httpClient);

            // When: We send the request
            await paymentClient.CreatePaymentAsync(paymentRequest, includeQrCode : true);

            // Then
            mockHttp.VerifyNoOutstandingExpectation();
        }
Esempio n. 13
0
        public async Task CanCreateDefaultPaymentWithOnlyRequiredFields()
        {
            // When: we create a payment request with only the required parameters
            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = DefaultRedirectUrl
            };

            // When: We send the payment request to Mollie
            PaymentResponse result = await PaymentClient.CreatePaymentAsync(paymentRequest);

            // Then: Make sure we get a valid response
            Assert.IsNotNull(result);
            Assert.AreEqual(paymentRequest.Amount.Currency, result.Amount.Currency);
            Assert.AreEqual(paymentRequest.Amount.Value, result.Amount.Value);
            Assert.AreEqual(paymentRequest.Description, result.Description);
            Assert.AreEqual(paymentRequest.RedirectUrl, result.RedirectUrl);
        }
Esempio n. 14
0
        public async Task PaymentWithDifferentHttpInstance()
        {
            // If: We create a PaymentClient with our own HttpClient instance
            HttpClient     myHttpClientInstance = new HttpClient();
            PaymentClient  paymentClient        = new PaymentClient(this.GetApiKeyFromConfiguration(), myHttpClientInstance);
            PaymentRequest paymentRequest       = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = this.DefaultRedirectUrl
            };

            // When: I create a new payment
            PaymentResponse result = await paymentClient.CreatePaymentAsync(paymentRequest);

            // Then: It should still work... lol
            Assert.IsNotNull(result);
            Assert.AreEqual(paymentRequest.Amount.Currency, result.Amount.Currency);
            Assert.AreEqual(paymentRequest.Amount.Value, result.Amount.Value);
            Assert.AreEqual(paymentRequest.Description, result.Description);
            Assert.AreEqual(paymentRequest.RedirectUrl, result.RedirectUrl);
        }
Esempio n. 15
0
        public async Task CanCreatePaymentWithMandate()
        {
            // If: We create a payment with a mandate id
            MandateResponse validMandate = await GetFirstValidMandate();

            CustomerResponse customer = await CustomerClient.GetCustomerAsync(validMandate.Links.Customer);

            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount       = new Amount(Currency.EUR, "100.00"),
                Description  = "Description",
                RedirectUrl  = DefaultRedirectUrl,
                SequenceType = SequenceType.Recurring,
                CustomerId   = customer.Id,
                MandateId    = validMandate.Id
            };

            // When: We send the payment request to Mollie
            PaymentResponse result = await PaymentClient.CreatePaymentAsync(paymentRequest);

            // Then: Make sure we get the mandate id back in the details
            Assert.AreEqual(validMandate.Id, result.MandateId);
        }
Esempio n. 16
0
        public async Task CanCreatePaymentAndRetrieveIt()
        {
            // If: we create a new payment request
            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = DefaultRedirectUrl,
                Locale      = Locale.de_DE
            };

            // When: We send the payment request to Mollie and attempt to retrieve it
            PaymentResponse paymentResponse = await PaymentClient.CreatePaymentAsync(paymentRequest);

            PaymentResponse result = await PaymentClient.GetPaymentAsync(paymentResponse.Id);

            // Then
            Assert.IsNotNull(result);
            Assert.AreEqual(paymentResponse.Id, result.Id);
            Assert.AreEqual(paymentResponse.Amount.Currency, result.Amount.Currency);
            Assert.AreEqual(paymentResponse.Amount.Value, result.Amount.Value);
            Assert.AreEqual(paymentResponse.Description, result.Description);
            Assert.AreEqual(paymentResponse.RedirectUrl, result.RedirectUrl);
        }
Esempio n. 17
0
        public async Task CreatePaymentAsync_PaymentWithRequiredParameters_ResponseIsDeserializedInExpectedFormat()
        {
            // Given: we create a payment request with only the required parameters
            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = "Description",
                RedirectUrl = "http://www.mollie.com"
            };
            const string jsonToReturnInMockResponse = defaultPaymentJsonResponse;

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When($"{BaseMollieClient.ApiEndPoint}*")
            .Respond("application/json", jsonToReturnInMockResponse);
            HttpClient    httpClient    = mockHttp.ToHttpClient();
            PaymentClient paymentClient = new PaymentClient("abcde", httpClient);

            // When: We send the request
            PaymentResponse paymentResponse = await paymentClient.CreatePaymentAsync(paymentRequest);

            // Then
            this.AssertPaymentIsEqual(paymentRequest, paymentResponse);
        }
Esempio n. 18
0
        public async Task CanCreateRecurringPaymentAndRetrieveIt()
        {
            // If: we create a new recurring payment
            MandateResponse mandate = await GetFirstValidMandate();

            CustomerResponse customer = await CustomerClient.GetCustomerAsync(mandate.Links.Customer);

            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount       = new Amount(Currency.EUR, "100.00"),
                Description  = "Description",
                RedirectUrl  = DefaultRedirectUrl,
                SequenceType = SequenceType.First,
                CustomerId   = customer.Id
            };

            // When: We send the payment request to Mollie and attempt to retrieve it
            PaymentResponse paymentResponse = await PaymentClient.CreatePaymentAsync(paymentRequest);

            PaymentResponse result = await PaymentClient.GetPaymentAsync(paymentResponse.Id);

            // Then: Make sure the recurringtype parameter is entered
            Assert.AreEqual(SequenceType.First, result.SequenceType);
        }
Esempio n. 19
0
        public void ShouldThrowMollieApiExceptionWhenInvalidParametersAreGiven()
        {
            // If: we create a payment request with invalid parameters
            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount      = new Amount(Currency.EUR, "100.00"),
                Description = null,
                RedirectUrl = null
            };

            // Then: Send the payment request to the Mollie Api, this should throw a mollie api exception
            AggregateException aggregateException = Assert.ThrowsException <AggregateException>(() => PaymentClient.CreatePaymentAsync(paymentRequest).Wait());
            MollieApiException mollieApiException = aggregateException.InnerExceptions.FirstOrDefault(x => x.GetType() == typeof(MollieApiException)) as MollieApiException;

            Assert.IsNotNull(mollieApiException);
            Assert.IsNotNull(mollieApiException.Details);
            Assert.IsTrue(!string.IsNullOrEmpty(mollieApiException.Details.Detail));
        }
Esempio n. 20
0
        public override string RedirectForPayment(OrderData orderData)
        {
            try
            {
                var appliedtotal = orderData.PurchaseInfo.GetXmlPropertyDouble("genxml/appliedtotal");
                var alreadypaid  = orderData.PurchaseInfo.GetXmlPropertyDouble("genxml/alreadypaid");

                var info = ProviderUtils.GetProviderSettings();

                string cartDesc  = info.GetXmlProperty("genxml/textbox/cartdescription");
                var    ApiKey    = info.GetXmlProperty("genxml/textbox/key");
                var    idealOnly = true; // default to previous behaviour
                if (info.XMLDoc.SelectSingleNode("genxml/checkbox/idealonly") != null)
                {
                    // take the value from the settings, if it exists
                    idealOnly = info.GetXmlPropertyBool("genxml/checkbox/idealonly");
                }
                var notifyUrl = Utils.ToAbsoluteUrl("/DesktopModules/NBright/OS_Mollie/notify.ashx");
                var returnUrl = Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "");

                //orderid/itemid
                var ItemId = orderData.PurchaseInfo.ItemID.ToString("");

                var productOrderNumber = orderData.OrderNumber;

                ////var nbi = new NBrightInfo();
                //nbi.XMLData = orderData.payselectionXml;
                //var paymentMethod = nbi.GetXmlProperty("genxml/textbox/paymentmethod");
                //var paymentBank = nbi.GetXmlProperty("genxml/textbox/paymentbank");
                //var apiKey = liveApiKey;

                string      specifier;
                CultureInfo culture;
                specifier = "F";
                culture   = CultureInfo.CreateSpecificCulture("en-US");
                var totalString       = decimal.Parse((appliedtotal - alreadypaid).ToString("0.00"));
                var totalPrijsString2 = totalString.ToString(specifier, culture).Replace('€', ' ').Trim();

                PaymentResponse result = null;
                if (idealOnly)
                {
                    IPaymentClient      paymentClient       = new PaymentClient(ApiKey);
                    IdealPaymentRequest paymentRequestIdeal = new IdealPaymentRequest()
                    {
                        Amount      = new Amount(Currency.EUR, totalPrijsString2),
                        Description = "Bestelling ID: " + " " + productOrderNumber + " " + cartDesc,
                        RedirectUrl = returnUrl + "/orderid/" + ItemId,
                        WebhookUrl  = notifyUrl + "?orderid=" + ItemId,
                        Locale      = Locale.nl_NL,
                        Method      = PaymentMethod.Ideal
                    };

                    var task = Task.Run(async() => (IdealPaymentResponse)await paymentClient.CreatePaymentAsync(paymentRequestIdeal));
                    task.Wait();
                    result = task.Result;
                }
                else
                {
                    IPaymentClient paymentClient  = new PaymentClient(ApiKey);
                    PaymentRequest paymentRequest = new PaymentRequest()
                    {
                        Amount      = new Amount(Currency.EUR, totalPrijsString2),
                        Description = "Bestelling ID: " + " " + productOrderNumber + " " + cartDesc,
                        RedirectUrl = returnUrl + "/orderid/" + ItemId,
                        WebhookUrl  = notifyUrl + "?orderid=" + ItemId,
                        Locale      = Locale.nl_NL,
                    };

                    var task = Task.Run(async() => await paymentClient.CreatePaymentAsync(paymentRequest));
                    task.Wait();
                    result = task.Result;
                }

                orderData.PaymentPassKey = result.Id;
                orderData.OrderStatus    = "020";
                orderData.PurchaseInfo.SetXmlProperty("genxml/paymenterror", "");
                orderData.PurchaseInfo.SetXmlProperty("genxml/posturl", result.Links.Checkout.Href);
                orderData.PurchaseInfo.Lang = Utils.GetCurrentCulture();
                orderData.SavePurchaseData();

                try
                {
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                    // objEventLog.AddLog("Betaling aangemaakt: ", "ID: " + result.Id + " Bedrag:" + result.Amount.Currency + " ItemId: " + ItemId, PortalSettings, -1, EventLogController.EventLogType.ADMIN_ALERT);

                    HttpContext.Current.Response.Clear();
                    //redirect naar Mollie
                    HttpContext.Current.Response.Redirect(result.Links.Checkout.Href);
                }
                catch (Exception ex)
                {
                    // rollback transaction
                    orderData.PurchaseInfo.SetXmlProperty("genxml/paymenterror", "<div>ERROR: Invalid payment data </div><div>" + ex + "</div>");
                    orderData.PaymentFail("010");
                    //objEventLog.AddLog("Betaling aanmaken mislukt: ", "ID: " + result.Id + " Bedrag:" + result.Amount.Currency + " ItemId: " + ItemId, PortalSettings, -1, EventLogController.EventLogType.ADMIN_ALERT);

                    var param = new string[3];
                    param[0] = "orderid=" + orderData.PurchaseInfo.ItemID.ToString("");
                    param[1] = "status=0";
                    return(Globals.NavigateURL(StoreSettings.Current.PaymentTabId, "", param));
                }
                try
                {
                    HttpContext.Current.Response.End();
                }
                catch (Exception ex)
                {
                    // this try/catch to avoid sending error 'ThreadAbortException'
                }

                return("");
            }
            catch (Exception ex)
            {
                //objEventLog.AddLog("Foutje", "Dus:" + ex.Message + " " + ex.InnerException , PortalSettings, -1, EventLogController.EventLogType.ADMIN_ALERT);
                return(ex.InnerException.ToString());
            }
        }
Esempio n. 21
0
        public async Task <IActionResult> Checkout(string invoiceId, [FromForm] int type)
        {
            using (var context = new OverstagContext())
            {
                var invoice     = context.Invoices.Include(a => a.Payment).Include(b => b.User).FirstOrDefault(f => f.InvoiceID == Uri.UnescapeDataString(invoiceId));
                var paymentType = (PayType)type;

                if (invoice == null)
                {
                    return(View("~/Views/Error/Custom.cshtml", new string[] { "Factuur niet gevonden", "De factuur die u probeert te betalen is niet gevonden. Probeer het opnieuw, en als het niet lukt neem dan contact met ons op" }));
                }

                ViewBag.Amount = invoice.Amount;

                Payment p = new Payment()
                {
                    InvoiceId = invoice.Id,
                    PayType   = paymentType,
                    PlacedAt  = DateTime.Now,
                    UserId    = invoice.UserID
                };

                if (invoice.Payment != null)
                {
                    if (invoice.Payment.IsPaid())
                    {
                        invoice.Paid = true;
                        context.Invoices.Update(invoice);
                        await context.SaveChangesAsync();

                        return(View("~/Views/Error/Custom.cshtml", new string[] { "Factuur is al betaald.", "De factuur die u probeert te betalen is al betaald." }));
                    }

                    if (!invoice.Payment.IsFailed())
                    {
                        p = invoice.Payment;

#if MOLLIE_ENABLED
                        if (!p.IsPaid() && p.PayType == PayType.MOLLIE)
                        {
                            //Get url
                            PaymentClient   pc = new PaymentClient(Core.General.Credentials.mollieApiToken);
                            PaymentResponse ps = await pc.GetPaymentAsync(p.PaymentId);

                            if (ps.Links.Checkout != null) //Still open for payment
                            {
                                ViewBag.PayLink = ps.Links.Checkout.Href;
                            }
                        }
#endif

                        return(View(p));
                    }
                }


                switch (paymentType)
                {
                case PayType.MOLLIE:
                {
                    string cost     = Math.Round((double)invoice.Amount / 100, 2).ToString("F").Replace(",", ".");
                    string redirect = $"{string.Format("{0}://{1}", HttpContext.Request.Scheme, HttpContext.Request.Host)}/Pay/Invoice/{Uri.EscapeDataString(invoice.InvoiceID)}?showPayment=true";
                    string webhook  = $"{string.Format("{0}://{1}", HttpContext.Request.Scheme, HttpContext.Request.Host)}/Pay/Webhook";

                    PaymentClient       pc = new PaymentClient(Core.General.Credentials.mollieApiToken);
                    IdealPaymentRequest pr = new IdealPaymentRequest()
                    {
                        Amount      = new Amount(Currency.EUR, cost),
                        Description = $"Overstag factuur #{invoice.Id}",
                        RedirectUrl = redirect,
                        Locale      = "nl_NL",
                        CustomerId  = invoice.User.MollieID,
                        Metadata    = Uri.EscapeDataString(invoice.InvoiceID),
#if !DEBUG
                        WebhookUrl = webhook
#endif
                    };

#if MOLLIE_ENABLED
                    PaymentResponse ps = await pc.CreatePaymentAsync(pr);

                    ViewBag.PayLink = ps.Links.Checkout.Href;
                    p.PaymentId     = ps.Id;
                    p.Status        = ps.Status;
#endif
                }
                break;

                case PayType.BANK:
                    //Create payment request via bank or tikkie
                    p.Status = PaymentStatus.Open;
                    break;

                default:
                    return(View("~/Views/Error/Custom.cshtml", new string[] { "Betaalmethode niet ondersteund", "De betaalmethode die u heeft gekozen wordt niet ondersteund." }));
                }

                context.Payments.Add(p);
                await context.SaveChangesAsync();

                return(View(context.Payments.Include(x => x.Invoice).First(f => f.Invoice.InvoiceID == invoice.InvoiceID)));
            }
        }