public ActionResult SuccessPage() { string sessionState = Request.QueryString.Get("sessionState"); string sessionSubState = Request.QueryString.Get("sessionSubState"); var message = GopayHelper.GetResultMessage(sessionState, sessionSubState); ViewBag.Message = message; return(View()); }
public ActionResult FailedPage() { string sessionState = Request.QueryString.Get("sessionState"); string sessionSubState = Request.QueryString.Get("sessionSubState"); if (sessionState == null || sessionState == "") { sessionState = GopayHelper.SessionState.CANCELED.ToString(); } ViewBag.Message = GopayHelper.GetResultMessage(sessionState, sessionSubState); return(View()); }
/// <summary> /// Obsluha zpetneho volani po potvrzeni, zruseni platby /// </summary> /// /// <returns>URL</returns> public string Call( long returnedGoId, long returnedPaymentSessionId, string returnedOrderNumber, string returnedEncryptedSignature) { // // Nacist data objednavky dle prichoziho paymentSessionId, zde z testovacich duvodu vse primo v testovaci tride objednavka // Upravte dle ulozeni vasich objednavek // //eshop.Order objednavka = new eshop.Order(); //objednavka.loadByPaymentSessionId(returnedPaymentSessionId); var objednavka = new Order(); objednavka.OrderNumber = "123"; objednavka.ProductName = "itron"; objednavka.Currency = "EUR"; string location; try { GopayHelper.CheckPaymentIdentity( returnedGoId, returnedPaymentSessionId, null, returnedOrderNumber, returnedEncryptedSignature, Config.GOID, objednavka.OrderNumber, Config.SECURE_KEY); } catch (GopayException ex) { // Nevalidni informace z redirectu - fraud // Zalogovani dat, chyby... // Presmerovani na error page return(Config.FAILED_URL + "?sessionState=" + GopayHelper.SessionState.FAILED); } // Kontrola zaplacenosti objednavky na serveru GoPay CallbackResult callbackResult = GopayHelperWS.IsPaymentDone( returnedPaymentSessionId, returnedGoId, returnedOrderNumber, objednavka.TotalPrice, objednavka.Currency, objednavka.ProductName, Config.SECURE_KEY); // Zpracovani objednavky, prezentace uspesne platby // ... // ... // ... if (callbackResult.sessionState == GopayHelper.SessionState.PAID.ToString()) { // // Zpracovat pouze objednavku, ktera jeste nebyla zaplacena // if (objednavka.State != GopayHelper.SessionState.PAID.ToString()) { // // Zpracovani objednavky ! UPRAVTE ! // //objednavka.ProcessPayment(); } // // Presmerovani na prezentaci uspesne platby // location = Config.SUCCESS_URL; } else if (callbackResult.sessionState == GopayHelper.SessionState.PAYMENT_METHOD_CHOSEN.ToString()) { // Platba ceka na zaplaceni location = Config.SUCCESS_URL; } else if (callbackResult.sessionState == GopayHelper.SessionState.CREATED.ToString()) { // Platba nebyla zaplacena location = Config.FAILED_URL; } else if (callbackResult.sessionState == GopayHelper.SessionState.CANCELED.ToString()) { // Platba byla zrusena objednavajicim //objednavka.CancelPayment(); location = Config.FAILED_URL; } else if (callbackResult.sessionState == GopayHelper.SessionState.TIMEOUTED.ToString()) { // Platnost platby vyprsela //objednavka.TimeoutPayment(); location = Config.FAILED_URL; } else if (callbackResult.sessionState == GopayHelper.SessionState.AUTHORIZED.ToString()) { // Platba byla autorizovana, ceka se na dokonceni //objednavka.AutorizePayment(); location = Config.SUCCESS_URL; } else if (callbackResult.sessionState == GopayHelper.SessionState.REFUNDED.ToString()) { // Platba byla vracena - refundovana //objednavka.RefundePayment(); location = Config.SUCCESS_URL; } else { // Chyba ve stavu platby location = Config.FAILED_URL; callbackResult.sessionState = GopayHelper.SessionState.FAILED.ToString(); } return(location + "?sessionState=" + callbackResult.sessionState + "&sessionSubState=" + callbackResult.sessionSubState); }
/// <summary> /// Zalozeni platby pomoci WS - na strane gopay /// </summary> /// /// <returns>URL pro presmerovani</returns> public string Pay() { long paymentSessionId; // // Nacist data objednavky, zde z testovacich duvodu vse primo v testovaci tride objednavka // Upravte dle ulozeni vasich objednavek // var objednavka = new Order(); objednavka.ProductName = "itron"; objednavka.Currency = "EUR"; objednavka.OrderNumber = "123"; objednavka.FirstName = "Pavol"; objednavka.LastName = "Decky"; objednavka.City = "Zilina"; objednavka.Street = "Pod Vinicou"; objednavka.PostalCode = "01004"; objednavka.CountryCode = "SVK"; objednavka.Email = "*****@*****.**"; objednavka.PhoneNumber = "0949554535"; try { // // Vytvoreni platby na strane GoPay prostrednictvim API funkce // Pokud vytvoreni probehne korektne, je navracen identifikator paymentSessionId // paymentSessionId = GopayHelperWS.CreatePayment( Config.GOID, objednavka.ProductName, objednavka.TotalPrice, objednavka.Currency, objednavka.OrderNumber, Config.CALLBACK_URL, Config.CALLBACK_URL, this.paymentChannels, defaultPaymentChannel, Config.SECURE_KEY, objednavka.FirstName, objednavka.LastName, objednavka.City, objednavka.Street, objednavka.PostalCode, objednavka.CountryCode, objednavka.Email, objednavka.PhoneNumber, p1, p2, p3, p4, Config.LANG); } catch (GopayException ex) { // Zachyceni chyby, zalogovani chyby // ... return(Config.FAILED_URL + "?sessionState=" + GopayHelper.SessionState.FAILED); } // Platba na strane GoPay uspesne vytvorena // Ulozeni paymentSessionId k objednavce. Slouzi pro komunikaci s GoPay // ... objednavka.PaymentSessionId = paymentSessionId; string ecryptedSignature = GopayHelper.Encrypt( GopayHelper.Hash( GopayHelper.ConcatPaymentSession( Config.GOID, paymentSessionId, Config.SECURE_KEY) ), Config.SECURE_KEY); // Presmerovani na platebni branu return(GopayConfig.FullIntegrationUrl + "?sessionInfo.targetGoId=" + Config.GOID + "&sessionInfo.paymentSessionId=" + paymentSessionId + "&sessionInfo.encryptedSignature=" + ecryptedSignature); }