コード例 #1
0
ファイル: CardcomManager.cs プロジェクト: RcBuilder/Scripts
        public (string Raw, NameValueCollection Details) CancelRecurringCharge(
            string Code,
            int RecurringId,
            string ProductName,
            CardcomInvoiceDetails InvoiceDetails,
            byte Currency = 1
            )
        {
            // http://kb.cardcom.co.il/article/AA-00444/0
            var prms = new Dictionary <string, string>();

            prms["TerminalNumber"] = this.Terminal;
            prms["UserName"]       = this.UserName;
            prms["APILevel"]       = API_LEVEL;
            prms["codepage"]       = UNICODE;

            prms["RecurringPayments.ChargeInTerminal"] = this.TerminalNoCvv;
            prms["Operation"]                     = "Update"; // NewAndUpdate, Update
            prms["LowProfileDealGuid"]            = Code;
            prms["RecurringPayments.RecurringId"] = RecurringId.ToString();

            prms["Account.CompanyName"] = InvoiceDetails.CustomerName;
            prms["Account.RegisteredBusinessNumber"] = InvoiceDetails.CustomerId;
            prms["Account.SiteUniqueId"]             = InvoiceDetails.CustomerId;
            prms["Account.Email"] = InvoiceDetails.Email;

            prms["RecurringPayments.FlexItem.Price"]              = "0"; // Sum To Bill;
            prms["RecurringPayments.TotalNumOfBills"]             = "1";
            prms["RecurringPayments.InternalDecription"]          = ProductName;
            prms["RecurringPayments.FlexItem.InvoiceDescription"] = ProductName;

            // CANCEL!
            prms["RecurringPayments.IsActive"] = "false";  // boolean: false = no charges, true = recurring charges

            // billing coin: 1 - NIS, 2 - USD...
            // list: http://kb.cardcom.co.il/article/AA-00247/0
            prms["RecurringPayments.FinalDebitCoinId"] = Currency.ToString();

            if (!string.IsNullOrEmpty(this.NotifyURL))
            {
                prms["IndicatorUrl"] = this.NotifyURL; // IPN Listener
            }
            using (var client = new WebClient())
            {
                #region ### Response Parameters ###

                /*
                 *  ResponseCode
                 */
                #endregion

                client.Encoding = Encoding.UTF8;
                var response       = client.UploadString(RECURRING_PAYMENT_ENDPOINT, string.Join("&", prms.Select(x => $"{x.Key}={x.Value}")));
                var responseText   = HttpUtility.UrlDecode(response);
                var responseParsed = new NameValueCollection(HttpUtility.ParseQueryString(response));

                var StatusCode = Convert.ToInt32(responseParsed["ResponseCode"]);

                /*
                 * if (StatusCode != 0)
                 *  LoggerSingleton.Instance.Info("Cardcom", $"CancelRecurringCharge #{Code} Failed With Code {StatusCode}", new List<string> {
                 *      responseText
                 *  });
                 */
                return(responseText, responseParsed);
            }
        }
コード例 #2
0
ファイル: CardcomManager.cs プロジェクト: RcBuilder/Scripts
        public (string Raw, NameValueCollection Details) ChargeWithToken(
            string Token,
            string CardExpiry /*YYYYMM*/,
            string CardOwnerId,
            List <CardcomIFrameSourceItem> Items,
            string ReturnValue,
            int NumOfPayments = 1,
            byte Currency     = 1,
            CardcomInvoiceDetails InvoiceDetails = null,
            List <string> CustomFields           = null
            )
        {
            // http://kb.cardcom.co.il/article/AA-00253/0
            var prms = new Dictionary <string, string>();

            prms["TerminalNumber"] = this.Terminal;
            prms["UserName"]       = this.UserName;
            prms["APILevel"]       = API_LEVEL;
            prms["codepage"]       = UNICODE;

            prms["TokenToCharge.Token"]        = Token;
            prms["TokenToCharge.UniqAsmachta"] = Token;

            if (!string.IsNullOrEmpty(CardExpiry))
            {
                prms["TokenToCharge.CardValidityMonth"] = CardExpiry?.Substring(4, 2);
                prms["TokenToCharge.CardValidityYear"]  = CardExpiry?.Substring(2, 2);
            }

            prms["TokenToCharge.SumToBill"]      = Items.Sum(x => x.Price * x.Quantity).ToString(); // Sum To Bill;
            prms["TokenToCharge.IdentityNumber"] = CardOwnerId;
            prms["TokenToCharge.NumOfPayments"]  = NumOfPayments.ToString();

            // billing coin: 1 - NIS, 2 - USD...
            // list: http://kb.cardcom.co.il/article/AA-00247/0
            prms["TokenToCharge.CoinID"] = Currency.ToString();

            // value that will be return with the IPN
            prms["ReturnValue"] = ReturnValue;

            if (!string.IsNullOrEmpty(this.NotifyURL))
            {
                prms["IndicatorUrl"] = this.NotifyURL; // IPN Listener
            }
            // http://kb.cardcom.co.il/article/AA-00403/0
            var cfIndex = 1;

            CustomFields?.ForEach(x => {
                prms[$"CustomFields.Field{cfIndex}"] = x;
                cfIndex++;
            });

            // unique id for each transaction (to prevent duplicates)
            /// prms["TokenToCharge.UniqAsmachta"] = "..."

            if (InvoiceDetails != null)
            {
                // http://kb.cardcom.co.il/article/AA-00244/0
                prms["InvoiceHead.CustName"]    = InvoiceDetails.CustomerName;
                prms["InvoiceHead.SendByEmail"] = InvoiceDetails.SendEmail.ToString(); // will the invoice be send by email to the customer
                prms["InvoiceHead.Language"]    = LANGUAGE_CODE;                       // he or en only
                prms["InvoiceHead.Email"]       = InvoiceDetails.Email;                // value that will be return and save in CardCom system

                /// NOTE! Sum of all Lines Price*Quantity  must be equals to SumToBil
                var itemIndex = 1;
                Items?.ForEach(x =>
                {
                    prms[$"InvoiceLines{itemIndex}.Description"] = x.Description ?? "";
                    prms[$"InvoiceLines{itemIndex}.Price"]       = x.Price.ToString();
                    prms[$"InvoiceLines{itemIndex}.Quantity"]    = x.Quantity.ToString();
                    itemIndex++;
                });
            }

            using (var client = new WebClient())
            {
                #region ### Response Parameters ###

                /*
                 *  http://kb.cardcom.co.il/article/AA-00253/0
                 *  ResponseCode
                 *  Description
                 *  InternalDealNumber
                 *  InvoiceResponse.ResponseCode
                 *  InvoiceResponse.Description
                 *  InvoiceResponse.InvoiceNumber
                 *  InvoiceResponse.InvoiceType
                 *  ApprovalNumber
                 */
                #endregion

                client.Encoding = Encoding.UTF8;
                var response       = client.UploadString(TOKEN_CHARGE_ENDPOINT, string.Join("&", prms.Select(x => $"{x.Key}={x.Value}")));
                var responseText   = HttpUtility.UrlDecode(response);
                var responseParsed = new NameValueCollection(HttpUtility.ParseQueryString(response));

                var StatusCode = Convert.ToInt32(responseParsed["ResponseCode"]);

                /*
                 * if (StatusCode != 0)
                 *  LoggerSingleton.Instance.Info("Cardcom", $"ChargeWithToken #{Token} Failed With Code {StatusCode}", new List<string> { responseText });
                 */
                return(responseText, responseParsed);
            }
        }
コード例 #3
0
ファイル: CardcomManager.cs プロジェクト: RcBuilder/Scripts
        public (string Raw, NameValueCollection Details) SetRecurringCharge(
            string Code,
            string ProductName,
            DateTime RecurringPaymentsStartDate,
            int TimeIntervalId,
            List <CardcomIFrameSourceItem> Items,
            string ReturnValue,
            CardcomInvoiceDetails InvoiceDetails,
            int NumOfPayments = 999999,
            byte Currency     = 1
            )
        {
            // http://kb.cardcom.co.il/article/AA-00444/0
            var prms = new Dictionary <string, string>();

            prms["TerminalNumber"] = this.Terminal;
            prms["UserName"]       = this.UserName;
            prms["APILevel"]       = API_LEVEL;
            prms["codepage"]       = UNICODE;

            prms["RecurringPayments.ChargeInTerminal"] = this.TerminalNoCvv;
            prms["Operation"]          = "NewAndUpdate"; // NewAndUpdate, Update
            prms["LowProfileDealGuid"] = Code;

            prms["Account.CompanyName"] = InvoiceDetails.CustomerName;
            prms["Account.RegisteredBusinessNumber"] = InvoiceDetails.CustomerId;
            prms["Account.SiteUniqueId"]             = InvoiceDetails.CustomerId;

            prms["Account.Email"] = InvoiceDetails.Email;

            prms["RecurringPayments.TimeIntervalId"]              = TimeIntervalId.ToString();                       // 1 = monthly, 2 = weekly, 3 = yearly (note! custom values defined in cardcom dashboard)
            prms["RecurringPayments.FlexItem.Price"]              = Items.Sum(x => x.Price * x.Quantity).ToString(); // Sum To Bill;
            prms["RecurringPayments.TotalNumOfBills"]             = NumOfPayments.ToString();                        // number of payments, one per week/month/year (depends on the TimeIntervalId)
            prms["RecurringPayments.InternalDecription"]          = ProductName;
            prms["RecurringPayments.FlexItem.InvoiceDescription"] = ProductName;
            prms["RecurringPayments.NextDateToBill"]              = RecurringPaymentsStartDate.ToString("dd/MM/yyyy"); // format: dd/MM/yyyy

            // billing coin: 1 - NIS, 2 - USD...
            // list: http://kb.cardcom.co.il/article/AA-00247/0
            prms["RecurringPayments.FinalDebitCoinId"] = Currency.ToString();

            // value that will be return with the IPN
            prms["RecurringPayments.ReturnValue"] = ReturnValue;

            if (!string.IsNullOrEmpty(this.NotifyURL))
            {
                prms["IndicatorUrl"] = this.NotifyURL; // IPN Listener
            }
            using (var client = new WebClient())
            {
                #region ### Response Parameters ###

                /*
                 *  ResponseCode
                 *  Description
                 *  TotalRecurring
                 *  IsNewAccount
                 *  AccountId
                 *  Recurring0.RecurringId
                 *  Recurring0.ReturnValue
                 *  Recurring0.IsNewRecurring
                 */
                #endregion

                client.Encoding = Encoding.UTF8;
                var response       = client.UploadString(RECURRING_PAYMENT_ENDPOINT, string.Join("&", prms.Select(x => $"{x.Key}={x.Value}")));
                var responseText   = HttpUtility.UrlDecode(response);
                var responseParsed = new NameValueCollection(HttpUtility.ParseQueryString(response));

                var StatusCode = Convert.ToInt32(responseParsed["ResponseCode"]);

                /*
                 * if (StatusCode != 0)
                 *  LoggerSingleton.Instance.Info("Cardcom", $"SetRecurringCharge #{Code} Failed With Code {StatusCode}", new List<string> { responseText });
                 */
                return(responseText, responseParsed);
            }
        }
コード例 #4
0
ファイル: CardcomManager.cs プロジェクト: RcBuilder/Scripts
        /// <summary>
        /// Generate an IFrame Source
        /// </summary>
        /// <param name="ProductName">Name Of the paid service</param>
        /// <param name="Items">
        /// Items in this purchase
        /// { Price, Quantity, Description }
        /// </param>
        /// <param name="ReturnValue">Value to pass to the IPN</param>
        /// <param name="MaxNumOfPayments">Max number of payments to show to the user</param>
        /// <param name="Operation">
        /// 1 - Bill Only
        /// 2 - Bill And Create Token
        /// 3 - Token Only
        /// 4 - Suspended Deal (Order)</param>
        /// <param name="CreditType">
        /// 1 - Direct
        /// 2 - Payments
        /// </param>
        /// <param name="Currency">
        /// 1 - NIS
        /// 2 - USD
        /// http://kb.cardcom.co.il/article/AA-00247/0
        /// </param>
        /// <param name="InvoiceDetails">Details about the invoce</param>
        /// <param name="CustomFields">Custom fields to pass to cardcom</param>
        /// <returns>Iframe src</returns>
        public CardcomIFrameSourceResponse GenerateIFrameSource(
            string ProductName,
            List <CardcomIFrameSourceItem> Items,
            string ReturnValue,
            int MaxNumOfPayments = 1,
            byte Operation       = 2,
            byte CreditType      = 1,
            byte Currency        = 1,
            CardcomInvoiceDetails InvoiceDetails = null,
            List <string> CustomFields           = null
            )
        {
            // http://kb.cardcom.co.il/article/AA-00402/0/
            var prms = new Dictionary <string, string>();

            prms["TerminalNumber"] = this.Terminal;
            prms["UserName"]       = this.UserName;
            prms["APILevel"]       = API_LEVEL;
            prms["codepage"]       = UNICODE;
            prms["Operation"]      = Operation.ToString();  // 1 - Bill Only, 2- Bill And Create Token, 3 - Token Only, 4 - Suspended Deal (Order);
            prms["CreditType"]     = CreditType.ToString(); // 1 - Direct, 2 - Payments

            if (MaxNumOfPayments > 1)
            {
                prms["MaxNumOfPayments"] = MaxNumOfPayments.ToString(); // max num of payments to show to the user
            }
            // billing coin: 1 - NIS, 2 - USD...
            // list: http://kb.cardcom.co.il/article/AA-00247/0
            prms["CoinID"] = Currency.ToString();

            prms["Language"]    = LANGUAGE_CODE;                                   // he, en, ru, ar
            prms["SumToBill"]   = Items.Sum(x => x.Price * x.Quantity).ToString(); // Sum To Bill
            prms["ProductName"] = ProductName;

            // value that will be return with the IPN
            prms["ReturnValue"] = ReturnValue;

            // (optional) can be defined in Cardcom dashboard
            if (!string.IsNullOrEmpty(this.SuccessURL))
            {
                prms["SuccessRedirectUrl"] = this.SuccessURL;
            }

            if (!string.IsNullOrEmpty(this.ErrorURL))
            {
                prms["ErrorRedirectUrl"] = this.ErrorURL;
            }

            if (!string.IsNullOrEmpty(this.NotifyURL))
            {
                prms["IndicatorUrl"] = this.NotifyURL; // IPN Listener
            }
            // prms["CancelType"] = "2"; // show Cancel button on start
            // prms["CancelUrl"] = "https://localhost:44373/Purchase/Cancel";

            // http://kb.cardcom.co.il/article/AA-00403/0
            var cfIndex = 1;

            CustomFields?.ForEach(x =>
            {
                prms[$"CustomFields.Field{cfIndex}"] = x;
                cfIndex++;
            });

            if (Operation == 3)
            {
                /*
                 *  ValidationType (J2 OR J5)
                 *  use J5 for a full check of the card (till the charge provider) and to save the amount for x days.
                 *  note! support must be set in your charge provider account
                 *
                 *  available values:
                 *  - 2 for J2
                 *  - 5 for J5
                 */
                prms["CreateTokenJValidateType"] = "5";
            }

            if (InvoiceDetails != null && Operation < 3) // available only for bill operations (1 and 2)
            {
                // http://kb.cardcom.co.il/article/AA-00244/0
                prms["InvoiceHead.CustName"]    = InvoiceDetails.CustomerName;
                prms["InvoiceHead.SendByEmail"] = InvoiceDetails.SendEmail.ToString(); // will the invoice be send by email to the customer
                prms["InvoiceHead.Language"]    = LANGUAGE_CODE;                       // he or en only
                prms["InvoiceHead.Email"]       = InvoiceDetails.Email;                // value that will be return and save in CardCom system

                /// NOTE! Sum of all Lines Price*Quantity  must be equals to SumToBil
                var itemIndex = 1;
                Items?.ForEach(x =>
                {
                    prms[$"InvoiceLines{itemIndex}.Description"] = x.Description ?? "";
                    prms[$"InvoiceLines{itemIndex}.Price"]       = x.Price.ToString();
                    prms[$"InvoiceLines{itemIndex}.Quantity"]    = x.Quantity.ToString();
                    itemIndex++;
                });
            }

            using (var client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;
                var response       = client.UploadString(GENERATE_URL_ENDPOINT, string.Join("&", prms.Select(x => $"{x.Key}={x.Value}")));
                var responseParsed = new NameValueCollection(HttpUtility.ParseQueryString(response));

                var StatusCode = Convert.ToInt32(responseParsed["ResponseCode"]);
                if (StatusCode != 0)
                {
                    var responseText = HttpUtility.UrlDecode(response);
                    ///LoggerSingleton.Instance.Info("Cardcom", $"GenerateIFrameSource Failed With Code {StatusCode}", new List<string> { responseText });
                }

                return(new CardcomIFrameSourceResponse
                {
                    StatusCode = StatusCode,
                    Description = responseParsed["Description"],
                    Code = responseParsed["LowProfileCode"],
                    URL = responseParsed["url"]
                });
            }
        }