Пример #1
0
            /// <summary>
            /// Make reversal/void a payment.
            /// </summary>
            /// <param name="amount">The amount.</param>
            /// <param name="currency">The currency.</param>
            /// <param name="paymentProperties">The payment properties of the authorization response.</param>
            /// <param name="extensionTransactionProperties">Optional extension transaction properties.</param>
            /// <returns>A task that can await until the void has completed.</returns>
            public Task <PaymentInfo> VoidPaymentAsync(decimal amount, string currency, PaymentProperty[] paymentProperties, ExtensionTransaction extensionTransactionProperties)
            {
                if (amount < this.terminalSettings.MinimumAmountAllowed)
                {
                    throw new CardPaymentException(CardPaymentException.AmountLessThanMinimumLimit, "Amount does not meet minimum amount allowed.");
                }

                if (this.processor == null)
                {
                    this.processor = CardPaymentManager.GetPaymentProcessor(this.merchantProperties, this.paymentConnectorName);
                }

                if (this.terminalSettings.MaximumAmountAllowed > 0 && amount > this.terminalSettings.MaximumAmountAllowed)
                {
                    throw new CardPaymentException(CardPaymentException.AmountExceedsMaximumLimit, "Amount exceeds the maximum amount allowed.");
                }

                PaymentInfo paymentInfo = new PaymentInfo();

                // Handle multiple chain connectors by returning single instance used in capture.
                IPaymentProcessor currentProcessor = null;

                PaymentProperty[] currentMerchantProperties = null;
                CardPaymentManager.GetRequiredConnector(this.merchantProperties, paymentProperties, this.processor, out currentProcessor, out currentMerchantProperties);

                Request  request  = CardPaymentManager.GetCaptureRequest(currentMerchantProperties, paymentProperties, amount, currency, this.terminalSettings.Locale, this.isTestMode, this.terminalSettings.TerminalId, cardCache, extensionTransactionProperties);
                Response response = currentProcessor.Void(request);

                CardPaymentManager.MapVoidResponse(response, paymentInfo);

                return(Task.FromResult(paymentInfo));
            }
Пример #2
0
            /// <summary>
            /// Make authorization payment.
            /// </summary>
            /// <param name="amount">The amount.</param>
            /// <param name="currency">The currency.</param>
            /// <param name="voiceAuthorization">The voice approval code (optional).</param>
            /// <param name="isManualEntry">If manual credit card entry is required.</param>
            /// <param name="extensionTransactionProperties">Optional extension transaction properties.</param>
            /// <returns>A task that can await until the authorization has completed.</returns>
            public async Task <PaymentInfo> AuthorizePaymentAsync(decimal amount, string currency, string voiceAuthorization, bool isManualEntry, ExtensionTransaction extensionTransactionProperties)
            {
                if (amount < this.terminalSettings.MinimumAmountAllowed)
                {
                    throw new CardPaymentException(CardPaymentException.AmountLessThanMinimumLimit, "Amount does not meet minimum amount allowed.");
                }

                if (this.terminalSettings.MaximumAmountAllowed > 0 && amount > this.terminalSettings.MaximumAmountAllowed)
                {
                    throw new CardPaymentException(CardPaymentException.AmountExceedsMaximumLimit, "Amount exceeds the maximum amount allowed.");
                }

                if (this.processor == null)
                {
                    this.processor = CardPaymentManager.GetPaymentProcessor(this.merchantProperties, this.paymentConnectorName);
                }

                PaymentInfo paymentInfo = new PaymentInfo();

                // Get tender
                TenderInfo maskedTenderInfo = await this.GetTenderAsync(true);

                if (maskedTenderInfo == null)
                {
                    return(paymentInfo);
                }

                paymentInfo.CardNumberMasked = maskedTenderInfo.CardNumber;
                paymentInfo.CashbackAmount   = maskedTenderInfo.CashBackAmount;
                paymentInfo.CardType         = (Microsoft.Dynamics.Commerce.HardwareStation.CardPayment.CardType)maskedTenderInfo.CardTypeId;

                if (paymentInfo.CashbackAmount > this.terminalSettings.DebitCashbackLimit)
                {
                    throw new CardPaymentException(CardPaymentException.CashbackAmountExceedsLimit, "Cashback amount exceeds the maximum amount allowed.");
                }

                // Authorize
                Response response = CardPaymentManager.ChainedAuthorizationCall(this.processor, this.merchantProperties, this.tenderInfo, amount, currency, this.terminalSettings.Locale, this.isTestMode, this.terminalSettings.TerminalId, extensionTransactionProperties);

                Guid cardStorageKey = Guid.NewGuid();

                CardPaymentManager.MapAuthorizeResponse(response, paymentInfo, cardStorageKey, this.terminalSettings.TerminalId);

                if (paymentInfo.IsApproved)
                {
                    // Backup credit card number
                    TemporaryCardMemoryStorage <string> cardStorage = new TemporaryCardMemoryStorage <string>(DateTime.UtcNow, this.tenderInfo.CardNumber);
                    cardStorage.StorageInfo = paymentInfo.PaymentSdkData;
                    cardCache.Add(cardStorageKey, cardStorage);

                    // need signature?
                    if (this.terminalSettings.SignatureCaptureMinimumAmount < paymentInfo.ApprovedAmount)
                    {
                        paymentInfo.SignatureData = await this.RequestTenderApprovalAsync(paymentInfo.ApprovedAmount);
                    }
                }

                return(paymentInfo);
            }
Пример #3
0
            /// <summary>
            /// Make refund payment.
            /// </summary>
            /// <param name="amount">The amount.</param>
            /// <param name="currency">The currency.</param>
            /// <param name="isManualEntry">If manual credit card entry is required.</param>
            /// <param name="extensionTransactionProperties">Optional extension transaction properties.</param>
            /// <returns>A task that can await until the refund has completed.</returns>
            public async Task <PaymentInfo> RefundPaymentAsync(decimal amount, string currency, bool isManualEntry, ExtensionTransaction extensionTransactionProperties)
            {
                if (amount < this.terminalSettings.MinimumAmountAllowed)
                {
                    throw new CardPaymentException(CardPaymentException.AmountLessThanMinimumLimit, "Amount does not meet minimum amount allowed.");
                }

                if (this.terminalSettings.MaximumAmountAllowed > 0 && amount > this.terminalSettings.MaximumAmountAllowed)
                {
                    throw new CardPaymentException(CardPaymentException.AmountExceedsMaximumLimit, "Amount exceeds the maximum amount allowed.");
                }

                if (this.processor == null)
                {
                    this.processor = CardPaymentManager.GetPaymentProcessor(this.merchantProperties, this.paymentConnectorName);
                }

                PaymentInfo paymentInfo = new PaymentInfo();

                // Get tender
                TenderInfo maskedTenderInfo = await this.GetTenderAsync(false);

                if (maskedTenderInfo == null)
                {
                    return(paymentInfo);
                }

                paymentInfo.CardNumberMasked = maskedTenderInfo.CardNumber;
                paymentInfo.CashbackAmount   = maskedTenderInfo.CashBackAmount;
                paymentInfo.CardType         = (Microsoft.Dynamics.Commerce.HardwareStation.CardPayment.CardType)maskedTenderInfo.CardTypeId;

                if (paymentInfo.CashbackAmount > this.terminalSettings.DebitCashbackLimit)
                {
                    throw new CardPaymentException(CardPaymentException.CashbackAmountExceedsLimit, "Cashback amount exceeds the maximum amount allowed.");
                }

                // Refund
                Response response = CardPaymentManager.ChainedRefundCall(this.processor, this.merchantProperties, this.tenderInfo, amount, currency, this.terminalSettings.Locale, this.isTestMode, this.terminalSettings.TerminalId, extensionTransactionProperties);

                CardPaymentManager.MapRefundResponse(response, paymentInfo);

                if (paymentInfo.IsApproved)
                {
                    // need signature?
                    if (this.terminalSettings.SignatureCaptureMinimumAmount < paymentInfo.ApprovedAmount)
                    {
                        paymentInfo.SignatureData = await this.RequestTenderApprovalAsync(paymentInfo.ApprovedAmount);
                    }
                }

                return(paymentInfo);
            }
Пример #4
0
            /// <summary>
            /// Fetch token for credit card.
            /// </summary>
            /// <param name="isManualEntry">The value indicating whether credit card should be entered manually.</param>
            /// <param name="extensionTransactionProperties">Optional extension transaction properties.</param>
            /// <returns>A task that can await until the token generation has completed.</returns>
            public async Task <PaymentInfo> FetchTokenAsync(bool isManualEntry, ExtensionTransaction extensionTransactionProperties)
            {
                PaymentInfo paymentInfo = new PaymentInfo();

                // Get tender
                TenderInfo maskedTenderInfo = await this.GetTenderAsync(false);

                if (maskedTenderInfo == null)
                {
                    return(paymentInfo);
                }

                if (this.processor == null)
                {
                    this.processor = CardPaymentManager.GetPaymentProcessor(this.merchantProperties, this.paymentConnectorName);
                }

                paymentInfo.CardNumberMasked = maskedTenderInfo.CardNumber;
                paymentInfo.CashbackAmount   = maskedTenderInfo.CashBackAmount;
                paymentInfo.CardType         = (Microsoft.Dynamics.Commerce.HardwareStation.CardPayment.CardType)maskedTenderInfo.CardTypeId;

                PaymentProperty[] defaultMerchantProperties = this.merchantProperties;

                if (this.merchantProperties[0].Namespace.Equals(GenericNamespace.Connector) && this.merchantProperties[0].Name.Equals(ConnectorProperties.Properties))
                {
                    defaultMerchantProperties = this.merchantProperties[0].PropertyList;
                }

                // Generate card token
                Request  request  = CardPaymentManager.GetTokenRequest(defaultMerchantProperties, this.tenderInfo, this.terminalSettings.Locale, extensionTransactionProperties);
                Response response = this.processor.GenerateCardToken(request, null);

                CardPaymentManager.MapTokenResponse(response, paymentInfo);

                return(paymentInfo);
            }