public IPaymentResponse Charge(PaymentRequest request) { var amount = CurrencyDecimalPlaceConverter.ToMinorUnit(request.Currency, request.TotalAmount); var req = new KpSessionRequest { PurchaseCurrency = request.Currency, PurchaseCountry = request.Country, OrderAmount = amount, OrderLines = new[] { new KpSessionRequest.OrderLine { Name = request.Name, Quantity = 1, UnitPrice = amount, TotalAmount = amount } }, }; var apiClient = new KlarnaApi(Setting, request.Country); var kpSession = apiClient.CreateKpSession(req); var urls = GetGetMerchantUrls(request); var hppSession = apiClient.CreateHppSession(kpSession.SessionId, urls); return(new RedirectResponse(hppSession.RedirectUrl, request.Id) { paymemtMethodReferenceId = hppSession.SessionId }); }
public IPaymentResponse Charge(PaymentRequest request) { var req = new KpSessionRequest { PurchaseCurrency = request.Currency, PurchaseCountry = request.Country, OrderAmount = request.TotalAmount, OrderLines = new[] { new KpSessionRequest.OrderLine { Name = request.Name, Quantity = 1, UnitPrice = request.TotalAmount, TotalAmount = request.TotalAmount } }, }; var callbackUrl = PaymentHelper.GetCallbackUrl(this, nameof(Notify), Context); var apiClient = new KlarnaApi(Setting, request.Country); var kpSession = apiClient.CreateKpSession(req); var hppSession = apiClient.CreateHppSession(kpSession.SessionId, Setting.GetGetMerchantUrls(callbackUrl, request.Id)); return(new RedirectResponse(hppSession.RedirectUrl, request.Id) { paymemtMethodReferenceId = hppSession.SessionId }); }
public PaymentStatusResponse checkStatus(PaymentRequest request) { var result = new PaymentStatusResponse { HasResult = true }; try { var hppSessionId = request.ReferenceId; var statusResponse = new KlarnaApi(Setting, request.Country).CheckStatus(hppSessionId); result.Status = ConvertStatus(statusResponse.Status); } catch (Exception ex) { Kooboo.Data.Log.Instance.Exception.WriteException(ex); } return(result); }
/// <summary> /// Klarna create order /// </summary> /// <param name="id">authorizationToken</param> /// <param name="processPaymentRequest"></param> /// <param name="orderId"></param> /// <param name="paymentId"></param> public ActionResult CreateOrder(string id, CheckoutModel processPaymentRequest, string orderId, string paymentId) { var settingResponse = _checkoutApi.PaymentSetting(PaymentMethodTypes.Klarna.ToString()); var setting = settingResponse.Result; var klarna = new KlarnaApi(setting); //var token = klarna.GenerateConsumerToken(processPaymentRequest, id); var orderResp = klarna.CreateOrder(processPaymentRequest, id, orderId, paymentId); var response = new BoolResponse { IsValid = false, Message = "" }; PaymentModel payment = null; if (orderResp.FraudStatus == "ACCEPTED") { var refOrderId = orderResp.RefOrderId; var orderResponse = _orderApi.GetOrdDetail(Sanitizer.GetSafeHtmlFragment(refOrderId)); var order = orderResponse.Result; payment = order.Payments.FirstOrDefault(x => x.Id == orderResp.PaymentId); payment.IsValid = true; payment.Status = PaymentStatus.Paid.GetHashCode(); payment.PaidAmount = (Convert.ToDecimal(orderResp.OrderAmount) / 100); payment.PspResponseCode = orderResp.OrderId; payment.PspResponseMessage = orderResp.FraudStatus; //payment.FraudScore = orderResp.FraudStatus; _checkoutApi.UpdatePayment(order.Id, payment); response = new BoolResponse { IsValid = true, RecordId = order.Id }; SetDataLayerVariables(order, WebhookEventTypes.CheckoutPayment); return(JsonSuccess(new { response = response, notificationUrl = setting.NotificationUrl }, JsonRequestBehavior.AllowGet)); } return(JsonSuccess(new { response = response, notificationUrl = setting.NotificationUrl }, JsonRequestBehavior.AllowGet)); }