Inhalte aufrufen

Profilbild

how to set 3D Secure

payment

Best Answer suat_suphi , 11 August 2023 - 21:13

I figured it out. 

 

1. 

public async Task<IActionResult> ConfirmOrder(string formData) 

call POS3DConfirm with returnURL = VirtualPOS3DResponse

 

2.

public IActionResult POS3DConfirm(OnlinePaymentCheckoutState model)
{
    return View(model);
}
results will return to this page VirtualPOS3DResponse
 
3.
[HttpPost]
[IgnoreAntiforgeryToken]
public async Task<IActionResult> VirtualPOS3DResponse()
{
    var messages = new List<string>();
    var store = Services.StoreContext.CurrentStore;
    try
    {
        Dictionary<string, object> pairs = _httpContextAccessor.HttpContext.Request.Form.Keys.ToDictionary(k => k, v => (object)_httpContextAccessor.HttpContext.Request.Form[v]);
        SaleResponse response = VPOSClient.Sale3DResponse(new Sale3DResponseRequest
        {
            responseArray = pairs
        }, await GetBankInfo(store.Id));
 
        if (response.statu == CP.VPOS.Enums.SaleResponseStatu.Success)
        {
            return RedirectToAction(nameof(OnlinePaymentController.POS3DConfirmCompleted), "OnlinePayment");
        }
        else
        {
            Logger.Error(response.message);
            NotifyError(response.message);
            return RedirectToAction(nameof(CheckoutController.PaymentMethod), "Checkout" );
        }
    }
    catch (Exception ex)
    {
        Logger.Error(ex.Message);
        NotifyError(ex.Message);
        return RedirectToAction(nameof(CheckoutController.PaymentMethod), "Checkout" );
    }
}

Sessions cannot be read in this method. Need the Completed method

 

4. 

 
        public IActionResult POS3DConfirmCompleted(OnlinePaymentCheckoutState model)
        {
            return RedirectToAction(nameof(CheckoutController.Confirm), "Checkout", model);
        }
Go to the full post


  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
4 Antworten zu diesem Thema

#1 suat_suphi

suat_suphi

    Member

  • Members
  • PunktPunkt
  • 24 Beiträge

Geschrieben: 22 July 2023 - 08:56

Hi,
 
 
this is a code for bank pos system. If payment3D's confirm is true, resp.message sends 3d page in string type. I couldn't find how to show this code with a popup to the screen or with a page and continue paying. could you help me ? not in any example. 
 

var result = new ProcessPaymentResult();
var settings = await CommonServices.SettingFactory.LoadSettingsAsync<OnlinePaymentSettings>(processPaymentRequest.StoreId);


var paymentData = _checkoutStateAccessor.CheckoutState.PaymentData;
result.AllowStoringCreditCardNumber = settings.AllowStoringCreditCardNumber == false ? false :
    bool.Parse((string)paymentData.Get("AllowStoringCreditCardNumber"));
//
result.NewPaymentStatus = PaymentStatus.Paid;
//
var customerInfo = GetCustomerInfo();
//
SaleRequest saleRequest = new SaleRequest
{
    invoiceInfo = customerInfo,
    shippingInfo = customerInfo,
    saleInfo = new SaleInfo
    {
        cardNameSurname = processPaymentRequest.CreditCardName,
        cardNumber = processPaymentRequest.CreditCardNumber,
        cardExpiryDateMonth = (short)processPaymentRequest.CreditCardExpireMonth,
        cardExpiryDateYear = ushort.Parse( "20" + (processPaymentRequest.CreditCardExpireYear.ToString().Length==1?"0":"") + processPaymentRequest.CreditCardExpireYear.ToString()),
        amount = (decimal)processPaymentRequest.OrderTotal,
        cardCVV = (string)processPaymentRequest.CreditCardCvv2,
        currency = (CP.VPOS.Enums.Currency?)GetCurrencyCode(_services.CurrencyService.PrimaryCurrency.CurrencyCode),
        installment = 1,  
    },
    payment3D = new Payment3D
    {
        confirm = true,
        returnURL = "http://localhost:59318/OnlinePaymentMethod/VirtualPOS3DResponse/"
    },
    customerIPAddress = _webHelper.GetClientIpAddress().ToString(),
    orderNumber = processPaymentRequest.OrderGuid.ToString() 
};
 

 SaleResponse resp = VPOSClient.Sale(saleRequest, await GetBankInfo());
 _httpContextAccessor.HttpContext.Session.SetString("OnlinePaymentResponseStatus", resp.message);
 if (resp.statu == CP.VPOS.Enums.SaleResponseStatu.Success)
 {
     result.AuthorizationTransactionResult = resp.transactionId;
     return result;
 
 }
 else if (resp.statu == CP.VPOS.Enums.SaleResponseStatu.RedirectHTML)
 {
     // if confirm of payment3D is true, resp.message is sending page as html 
     // resp.message
     return result;
    
 }
 else
 {
     throw new PaymentException(T("Plugins.Payments.Online.VPOSResponseError") + ": " + resp.message.ToString());
 }




#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 24 July 2023 - 13:49

Server-side ProcessPaymentAsync is too late for this flow to work. Order placement is already in progress here. It must be done earlier on confirm page and it must be done client-side to be able to display a popup dialog or to redirect to a 3D secure page. Typically this VPOSClient.Sale request is to be done using AJAX.


  • suat_suphi gefällt das

Marcus Gesing

Smartstore AG


#3 suat_suphi

suat_suphi

    Member

  • Members
  • PunktPunkt
  • 24 Beiträge

Geschrieben: 03 August 2023 - 23:36

Server-side ProcessPaymentAsync is too late for this flow to work. Order placement is already in progress here. It must be done earlier on confirm page and it must be done client-side to be able to display a popup dialog or to redirect to a 3D secure page. Typically this VPOSClient.Sale request is to be done using AJAX.

 

if I use to redirect to a 3d secure page, the session of OrderPaymentInfo is deleted when I come back. What can I do so that it is not deleted? Do I have to use a popup in an iframe?

 

<ProcessPaymentRequest>("OrderPaymentInfo", 



#4 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3801 Beiträge

Geschrieben: 04 August 2023 - 10:53

This should rarely happen, though, because a session doesn't expire that quickly. You can redirect the buyer back to the payment method page or the shopping cart page and display a notification that the session has expired and he has to go through the checkout again.
 
The alternative would be to have your plugin store the required data in the database (e.g. as GenericAttribute). This way they won't get lost. However, in such cases I prefer to run through the checkout again.

Marcus Gesing

Smartstore AG


#5 suat_suphi

suat_suphi

    Member

  • Members
  • PunktPunkt
  • 24 Beiträge

Geschrieben: 11 August 2023 - 21:13   Best Answer

I figured it out. 

 

1. 

public async Task<IActionResult> ConfirmOrder(string formData) 

call POS3DConfirm with returnURL = VirtualPOS3DResponse

 

2.

public IActionResult POS3DConfirm(OnlinePaymentCheckoutState model)
{
    return View(model);
}
results will return to this page VirtualPOS3DResponse
 
3.
[HttpPost]
[IgnoreAntiforgeryToken]
public async Task<IActionResult> VirtualPOS3DResponse()
{
    var messages = new List<string>();
    var store = Services.StoreContext.CurrentStore;
    try
    {
        Dictionary<string, object> pairs = _httpContextAccessor.HttpContext.Request.Form.Keys.ToDictionary(k => k, v => (object)_httpContextAccessor.HttpContext.Request.Form[v]);
        SaleResponse response = VPOSClient.Sale3DResponse(new Sale3DResponseRequest
        {
            responseArray = pairs
        }, await GetBankInfo(store.Id));
 
        if (response.statu == CP.VPOS.Enums.SaleResponseStatu.Success)
        {
            return RedirectToAction(nameof(OnlinePaymentController.POS3DConfirmCompleted), "OnlinePayment");
        }
        else
        {
            Logger.Error(response.message);
            NotifyError(response.message);
            return RedirectToAction(nameof(CheckoutController.PaymentMethod), "Checkout" );
        }
    }
    catch (Exception ex)
    {
        Logger.Error(ex.Message);
        NotifyError(ex.Message);
        return RedirectToAction(nameof(CheckoutController.PaymentMethod), "Checkout" );
    }
}

Sessions cannot be read in this method. Need the Completed method

 

4. 

 
        public IActionResult POS3DConfirmCompleted(OnlinePaymentCheckoutState model)
        {
            return RedirectToAction(nameof(CheckoutController.Confirm), "Checkout", model);
        }

  • stefanmueller gefällt das


Auch markiert mit einem oder mehrerer dieser Schlüsselwörter: payment