/// <summary>
        /// Get payment information
        /// </summary>
        /// <param name="form">The parsed form values</param>
        /// <returns>Payment info holder</returns>
        public virtual ProcessPaymentRequest GetPaymentInfo(IFormCollection form)
        {
            var paymentInfo = new ProcessPaymentRequest();

            // Process info from the payment form
            if (!_workContext.CurrentCustomer.IsGuest() && _payExPaymentSettings.AllowCreateAgreement)
            {
                int.TryParse(form["payexagreement"], out int agreementId);
                bool createAgreement = !StringValues.IsNullOrEmpty(form["CreateAgreement"]) &&
                                       string.Compare(form["CreateAgreement"][0], "true", StringComparison.InvariantCultureIgnoreCase) == 0;
                // There are no dedicated fields we can use, so reuse PurchaseOrderNumber for agreement info.
                if (agreementId > 0)
                {
                    PayExAgreement agreement = _payExAgreementService.GetById(agreementId);
                    if (agreement != null && agreement.CustomerId == _workContext.CurrentCustomer.Id)
                    {
                        paymentInfo.CustomValues.Add(AgreementRefKey, agreement.AgreementRef);
                    }
                }
                else if (createAgreement)
                {
                    paymentInfo.CustomValues.Add(AgreementRefKey, "new");
                }
            }

            return(paymentInfo);
        }
Пример #2
0
        public virtual void InsertPayExAgreement(PayExAgreement payExAgreement)
        {
            if (payExAgreement == null)
            {
                throw new ArgumentNullException("payExAgreement");
            }

            _payExAgreementRepository.Insert(payExAgreement);
        }
Пример #3
0
        public virtual void DeletePayExAgreement(PayExAgreement record)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            _payExAgreementRepository.Delete(record);
        }
        private void UpdateAgreement(CompleteResult result, Order order)
        {
            // Check if the transaction is based on an agreement
            if (string.IsNullOrEmpty(result.AgreementRef))
            {
                return;
            }

            order.SubscriptionTransactionId = result.AgreementRef;
            // Check if the agreement already exists
            PayExAgreement agreement = _payExAgreementService.GetByAgreementRef(result.AgreementRef);

            if (agreement == null)
            {
                // Save the new agreement
                agreement = new PayExAgreement
                {
                    AgreementRef            = result.AgreementRef,
                    CustomerId              = order.Customer.Id,
                    MaxAmount               = _payExPaymentSettings.AgreementMaxAmount,
                    Name                    = result.MaskedNumber ?? "Sparat kort", // TODO
                    PaymentMethod           = result.PaymentMethod,
                    PaymentMethodExpireDate = result.PaymentMethodExpireDate,
                    PaymentMethodSystemName = order.PaymentMethodSystemName,
                    NumberOfUsages          = 1,
                    LastUsedDate            = DateTime.UtcNow,
                    CreatedDate             = DateTime.UtcNow,
                };
                _payExAgreementService.InsertPayExAgreement(agreement);
            }
            else
            {
                // Log usage
                agreement.NumberOfUsages++;
                agreement.LastUsedDate = DateTime.UtcNow;
                _payExAgreementService.UpdatePayExAgreement(agreement);
            }
        }