Esempio n. 1
0
        public bool Pagar(Pagamento pagamento)
        {
            var api     = new PaymentsApi();
            var payment = pagamento.ToPayment();
            var ret     = true;

            try
            {
                payment = (Payment)api.Create(payment);
                ret     = payment.PaymentStatus == "APPROVED";
            }
            catch (Exception e)
            {
                ret = false;
            }

            return(ret);
        }
Esempio n. 2
0
        /// <summary>
        /// Process a payment
        /// </summary>
        /// <param name="processPaymentRequest">Payment info required for an order processing</param>
        /// <returns>Process payment result</returns>
        public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            Log("ProcessPayment settings " + _simplifyPaymentSettings.ToString());

            var token = (string)processPaymentRequest.CustomValues["SIMPLIFY_TOKEN"];

            Log(string.Format("ProcessPayment token: {0}, order total: {1}, Order GUID {2}, Store ID {3}",
                              token, processPaymentRequest.OrderTotal, processPaymentRequest.OrderGuid, processPaymentRequest.StoreId));

            var currency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode.ToString();

            Log("ProcessPayment Currency " + currency);
            if (!ValidCurrency(currency))
            {
                var r = new ProcessPaymentResult();
                r.AddError(GetMsg("Plugins.Payments.Simplify.Payment.Error.Currency", currency));
                return(r);
            }

            if (String.IsNullOrEmpty(token))
            {
                var r = new ProcessPaymentResult();
                r.AddError(GetMsg("Plugins.Payments.Simplify.Payment.Error.Token"));
                return(r);
            }

            var storeName = _storeContext.CurrentStore.Name;
            var orderId   = processPaymentRequest.OrderGuid;

            Payment payment = new Payment();

            payment.Amount      = (long)(processPaymentRequest.OrderTotal * 100);
            payment.Currency    = currency;
            payment.Token       = token;
            payment.Description = string.Format(_localizationService.GetResource("Plugins.Payments.Simplify.Payment.Description"), storeName, orderId); // TODO l10n
            payment.Reference   = processPaymentRequest.OrderGuid.ToString();

            Log("ProcessPayment description: " + payment.Description);
            Log("ProcessPayment reference: " + payment.Reference);

            var result = new ProcessPaymentResult();

            try
            {
                payment = (Payment)_paymentsApi.Create(payment, GetAuth());

                Log(string.Format("ProcessPayment - payment {0} {1}", payment.Id, payment.PaymentStatus));

                if (payment.PaymentStatus.Equals("APPROVED"))
                {
                    Log("ProcessPayment - auth code: " + payment.AuthCode);
                    result.AuthorizationTransactionCode = payment.AuthCode;
                    result.AuthorizationTransactionId   = payment.Id;
                    result.NewPaymentStatus             = PaymentStatus.Paid;
                }
                else
                {
                    result.AddError(GetMsg("Plugins.Payments.Simplify.Payment.Declined"));
                }
            }
            catch (Exception e)
            {
                LogException("ProcessPayment", e);
                result.AddError(GetMsg("Plugins.Payments.Simplify.Payment.Exception"));
            }

            Log("ProcessPayment paymentStatus: " + result.NewPaymentStatus);
            return(result);
        }