コード例 #1
0
        /// <summary>
        /// Process recurring payment
        /// </summary>
        /// <param name="processPaymentRequest">Payment info required for an order processing</param>
        /// <returns>Process payment result</returns>
        public ProcessPaymentResult ProcessRecurringPayment(ProcessPaymentRequest processPaymentRequest)
        {
            ProcessPaymentResult result = new ProcessPaymentResult();

            if (!processPaymentRequest.IsRecurringPayment)
            {
                // This payment method doesn't actually handle scheduling recurring payments
                // Therefore the initial call to ProcessRecurringPayment - where it actually
                // ISN'T a recurring payment - is ignored.

                return(result);
            }

            Order order = orderService.GetOrderById(processPaymentRequest.InitialOrderId);

            if (order != null) // this needs an initial order to work (this is where subscriptionid is registered)
            {
                int  fraud         = 0;
                long transactionid = -1;
                int  pbsresponse   = -1;
                int  epayresponse  = -1;

                int merchant = Int32.Parse(ePayPaymentSettings.MerchantId);

                // Construct order identification for this recurring payment
                // This is done because the new order that will hold this payment is not fully constructed yet
                // thus no orderId is available
                string orderId = String.Format("{0}-rec-{1}", processPaymentRequest.InitialOrderId, DateTime.UtcNow.ToString("yyMMddHHmm"));

                // authorize subscription payment
                // instant capture!
                using (var subscriptionservice = new epay.subscriptionservice.Subscription())
                {
                    subscriptionservice.authorize(
                        merchant,                                                               // merchantid
                        Int32.Parse(order.SubscriptionTransactionId),                           // subscriptionid
                        orderId,                                                                // orderid
                        Convert.ToInt32(Math.Round(processPaymentRequest.OrderTotal, 2) * 100), // amount
                        Int32.Parse(EPayHelper.GetIsoCode(order.CustomerCurrencyCode)),         // currency
                        1,                                                                      // instantcapture
                        "",                                                                     // group
                        "",                                                                     // description
                        "",                                                                     // email
                        "",                                                                     // sms
                        "",                                                                     // ipaddress
                        ePayPaymentSettings.RemotePassword,                                     // pwd
                        ref fraud,
                        ref transactionid,
                        ref pbsresponse,
                        ref epayresponse);

                    if (epayresponse == -1 && pbsresponse == 0)
                    {
                        result.SubscriptionTransactionId  = order.SubscriptionTransactionId;
                        result.AuthorizationTransactionId = transactionid.ToString();
                        result.CaptureTransactionId       = transactionid.ToString();
                        result.CaptureTransactionResult   = String.Format("Captured: ({0})", transactionid);
                        result.NewPaymentStatus           = PaymentStatus.Paid;
                    }
                    else
                    {
                        int    epayresp         = -1;
                        string pbsresponsetext  = "";
                        var    epayresponsetext = "";

                        subscriptionservice.getPbsError(merchant, 2, pbsresponse, ePayPaymentSettings.RemotePassword, ref pbsresponsetext, ref epayresp);
                        subscriptionservice.getEpayError(merchant, 2, epayresponse, ePayPaymentSettings.RemotePassword, ref epayresponsetext, ref epayresp);

                        result.AddError(String.Format("Error processing recurring payment: PBS({0}) EPay({1})", pbsresponsetext, epayresponsetext));
                    }
                }
            }
            else
            {
                result.AddError("Initial order wasn't set for recurring payment.");
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Post process payment (used by payment gateways that require redirecting to a third-party URL)
        /// </summary>
        /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param>
        public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            string lang = EPayHelper.GetLangauge(Thread.CurrentThread.CurrentCulture).ToString();

            decimal orderTotal  = Math.Round(postProcessPaymentRequest.Order.OrderTotal, 2);
            string  amount      = (orderTotal * 100).ToString("0", CultureInfo.InvariantCulture);
            string  currency    = EPayHelper.GetIsoCode(postProcessPaymentRequest.Order.CustomerCurrencyCode);
            string  itemurl     = this.webHelper.GetStoreLocation(false);
            string  continueurl = itemurl + "Plugins/PaymentePay/PDTHandler";
            string  cancelurl   = itemurl + "Plugins/PaymentePay/CancelOrder";
            string  merchant    = ePayPaymentSettings.MerchantId;

            var orderHasRecurringItems = false;

            foreach (var item in postProcessPaymentRequest.Order.OrderItems)
            {
                orderHasRecurringItems = orderHasRecurringItems || (item.Product != null && item.Product.IsRecurring);
            }

            string ordernumber = postProcessPaymentRequest.Order.Id.ToString("D2");

            // ordernumber 1-9 must be with 0 in front, e.g. 01
            if (ordernumber.Length == 1)
            {
                ordernumber = "0" + ordernumber;
            }

            var remotePostHelper = new RemotePost
            {
                FormName = "ePay",
                Url      = itemurl + "Plugins/PaymentePay/Open"
            };

            remotePostHelper.Add("merchantnumber", merchant);
            remotePostHelper.Add("orderid", ordernumber);
            remotePostHelper.Add("amount", amount);
            remotePostHelper.Add("windowstate", ePayPaymentSettings.FullScreen ? "3" : "1");
            remotePostHelper.Add("language", lang);
            remotePostHelper.Add("currency", currency);
            remotePostHelper.Add("accepturl", continueurl);
            remotePostHelper.Add("callbackurl", continueurl);
            remotePostHelper.Add("declineurl", cancelurl);
            remotePostHelper.Add("authmail", ePayPaymentSettings.AuthMail);
            remotePostHelper.Add("authsms", ePayPaymentSettings.AuthSms);
            remotePostHelper.Add("group", ePayPaymentSettings.Group);
            remotePostHelper.Add("instantcapture", Convert.ToByte(ePayPaymentSettings.Instantcapture).ToString());
            remotePostHelper.Add("ownreceipt", Convert.ToByte(ePayPaymentSettings.OwnReceipt).ToString());
            remotePostHelper.Add("cms", "nopcommerce");
            remotePostHelper.Add("subscription", (orderHasRecurringItems) ? "1" : "0");

            string stringToMd5 = "";

            foreach (string key in remotePostHelper.Params)
            {
                stringToMd5 += "" + remotePostHelper.Params[key];
            }

            string md5Check = GetMd5(stringToMd5 + ePayPaymentSettings.Md5Secret);

            remotePostHelper.Add("md5key", md5Check);

            remotePostHelper.Post();
        }