MassPayRequestItemType
예제 #1
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object
            MassPayRequestType request = new MassPayRequestType();
             ReceiverInfoCodeType receiverInfoType = (ReceiverInfoCodeType)
                Enum.Parse(typeof(ReceiverInfoCodeType), receiverType.SelectedValue);

             request.ReceiverType = receiverInfoType;
            if (emailSubject.Value != "")
            {
                request.EmailSubject = emailSubject.Value;
            }

            // Processing a single masspay receiver.
            // You can add upto 250 receivers in one call
            MassPayRequestItemType massPayItem = new MassPayRequestItemType();
            CurrencyCodeType currency = (CurrencyCodeType)
                Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue);
            massPayItem.Amount = new BasicAmountType(currency, amount.Value);
            if (receiverInfoType.Equals(ReceiverInfoCodeType.EMAILADDRESS) && emailId.Value != "")
            {
                massPayItem.ReceiverEmail = emailId.Value;
            }
            else if (receiverInfoType.Equals(ReceiverInfoCodeType.PHONENUMBER) && phoneNumber.Value != "")
            {
                massPayItem.ReceiverPhone = phoneNumber.Value;
            }
            else if (receiverInfoType.Equals(ReceiverInfoCodeType.USERID) && receiverId.Value != "")
            {
                massPayItem.ReceiverID = receiverId.Value;
            }

            if (note.Value != "")
            {
                massPayItem.Note = note.Value;
            }
            if (uniqueId.Value != "")
            {
                massPayItem.UniqueId = uniqueId.Value;
            }
            request.MassPayItem.Add(massPayItem);

            // Invoke the API
            MassPayReq wrapper = new MassPayReq();
            wrapper.MassPayRequest = request;
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
            MassPayResponseType massPayResponse = service.MassPay(wrapper);

            // Check for API return status
            processResponse(service, massPayResponse);
        }
예제 #2
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object
            MassPayRequestType request = new MassPayRequestType();
             ReceiverInfoCodeType receiverInfoType = (ReceiverInfoCodeType)
                Enum.Parse(typeof(ReceiverInfoCodeType), receiverType.SelectedValue);

             request.ReceiverType = receiverInfoType;
             // (Optional) The subject line of the email that PayPal sends when the transaction completes. The subject line is the same for all recipients.
            if (emailSubject.Value != string.Empty)
            {
                request.EmailSubject = emailSubject.Value;
            }

            // (Required) Details of each payment.
            // Note:
            // A single MassPayRequest can include up to 250 MassPayItems.
            MassPayRequestItemType massPayItem = new MassPayRequestItemType();
            CurrencyCodeType currency = (CurrencyCodeType)
                Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue);
            massPayItem.Amount = new BasicAmountType(currency, amount.Value);

            // (Optional) How you identify the recipients of payments in this call to MassPay. It is one of the following values:
            // * EmailAddress
            // * UserID
            // * PhoneNumber
            if (receiverInfoType.Equals(ReceiverInfoCodeType.EMAILADDRESS) && emailId.Value != string.Empty)
            {
                massPayItem.ReceiverEmail = emailId.Value;
            }
            else if (receiverInfoType.Equals(ReceiverInfoCodeType.PHONENUMBER) && phoneNumber.Value != string.Empty)
            {
                massPayItem.ReceiverPhone = phoneNumber.Value;
            }
            else if (receiverInfoType.Equals(ReceiverInfoCodeType.USERID) && receiverId.Value != string.Empty)
            {
                massPayItem.ReceiverID = receiverId.Value;
            }

            if (note.Value != string.Empty)
            {
                massPayItem.Note = note.Value;
            }
            if (uniqueId.Value != string.Empty)
            {
                massPayItem.UniqueId = uniqueId.Value;
            }
            request.MassPayItem.Add(massPayItem);

            // Invoke the API
            MassPayReq wrapper = new MassPayReq();
            wrapper.MassPayRequest = request;

            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
            Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            // # API call
            // Invoke the MassPay method in service wrapper object
            MassPayResponseType massPayResponse = service.MassPay(wrapper);

            // Check for API return status
            processResponse(service, massPayResponse);
        }
        private void PerformPaypalRollinNewsWritersPayment(CreateInvoiceReturn output)
        {
            try
            {
                var status = (byte)InvoiceStatus.Payment_Awaiting_For_Mass_Payout;
                var dc = new ManagementContext();
                var invoices = dc.Invoices.Include("InvoiceBilling").Include("WriterPayouts").Where(x => x.InvoiceStatus == status).ToList();


                // Create request object
                List<Fund> tempFundsBeingPaid = new List<Fund>();
                MassPayRequestType request = new MassPayRequestType();
                ReceiverInfoCodeType receiverInfoType = ReceiverInfoCodeType.EMAILADDRESS;

                request.ReceiverType = receiverInfoType;
                // (Optional) The subject line of the email that PayPal sends when the transaction completes. The subject line is the same for all recipients.
                request.EmailSubject = "Payment For Rollin News Content " + DateTime.UtcNow.ToString("yyyy/MM/dd");

                foreach (var invoice in invoices)
                {
                    var payout = invoice.WriterPayouts.FirstOrDefault();

                    //gotta check if we are already paying this user.
                    var f = tempFundsBeingPaid.Where(x => x.UserId == payout.UserPaidId).FirstOrDefault();
                    if (f != null)
                    {
                        if (f.ActiveInUserAccount >= (f.AmountToWithdraw + (double)invoice.BasePriceForItems))
                        {
                            f.AmountToWithdraw += (double)payout.PriceAfterFees;
                            f.AmountToDeductFromTotal += (double)invoice.BasePriceForItems;

                        }
                    }
                    else
                    {
                        var fundSettings = Fund.GetCurrentFundsInformation(payout.UserPaidId);
                        if ((double)invoice.BasePriceForItems <= fundSettings.ActiveInUserAccount)
                        {
                            fundSettings.AmountToWithdraw += (double)payout.PriceAfterFees;
                            fundSettings.AmountToDeductFromTotal += (double)invoice.BasePriceForItems;
                            tempFundsBeingPaid.Add(fundSettings);
                        }
                    }

                }
                for (int i = 0; i < tempFundsBeingPaid.Count; i++)
                {
                    // (Required) Details of each payment.
                    // Note:
                    // A single MassPayRequest can include up to 250 MassPayItems.
                    MassPayRequestItemType massPayItem = new MassPayRequestItemType();
                    CurrencyCodeType currency = CurrencyCodeType.USD;
                    massPayItem.Amount = new BasicAmountType(currency, tempFundsBeingPaid[i].AmountToWithdraw.ToString("N2"));
                    massPayItem.ReceiverEmail = tempFundsBeingPaid[i].PaypalAddress;
                    massPayItem.Note = "Thanks for writing for Rollin News!  We appreciate your content. ID:" + invoice.InvoiceId.ToString().Replace("-", "");
                    if (!String.IsNullOrEmpty(tempFundsBeingPaid[i].PaypalAddress))
                        request.MassPayItem.Add(massPayItem);

                }

                // Invoke the API
                MassPayReq wrapper = new MassPayReq();
                wrapper.MassPayRequest = request;


                // Create the PayPalAPIInterfaceServiceService service object to make the API call
                PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();

                // # API call 
                // Invoke the MassPay method in service wrapper object  
                MassPayResponseType massPayResponse = service.MassPay(wrapper);

                // Display response values. 
                Dictionary<string, string> keyResponseParams = new Dictionary<string, string>();
                if (!(massPayResponse.Ack == AckCodeType.FAILURE) &&
                    !(massPayResponse.Ack == AckCodeType.FAILUREWITHWARNING))
                {


                    if (!(massPayResponse.Ack == AckCodeType.SUCCESS))
                    {

                        SendErrorsOfMassPayToAdmins(output, massPayResponse);
                        ErrorDatabaseManager.AddException(new Exception("MASSPAYERROR"), GetType(), additionalInformation: Newtonsoft.Json.JsonConvert.SerializeObject(tempFundsBeingPaid) + "______" + Newtonsoft.Json.JsonConvert.SerializeObject(massPayResponse));

                    }

                    for (int i = 0; i < tempFundsBeingPaid.Count; i++)
                    {
                        try
                        {
                            var user = SiteCache.GetPublicMemberFullWithUserId(tempFundsBeingPaid[i].UserId);
                            bool success = Fund.UpdateAmounts(tempFundsBeingPaid[i].UserId, tempFundsBeingPaid[i].TotalPaidToUser);

                            var emailData = new Dictionary<string, string> 
                            { 
                            { "derbyName", user.DerbyName},
                            {"amountPaid", tempFundsBeingPaid[i].AmountToDeductFromTotal.ToString("N2")}};
                            EmailServer.EmailServer.SendEmail(RollinNewsConfig.DEFAULT_EMAIL, RollinNewsConfig.DEFAULT_EMAIL_FROM_NAME, user.UserName, EmailServer.EmailServer.DEFAULT_SUBJECT_ROLLIN_NEWS + " You Were Just Paid!", emailData, EmailServer.EmailServerLayoutsEnum.RNPaymentJustPaid);
                        }
                        catch (Exception exception)
                        {
                            ErrorDatabaseManager.AddException(exception, exception.GetType());
                        }
                    }
                    var emailDataComplete = new Dictionary<string, string> { { "totalPaid", tempFundsBeingPaid.Sum(x=>x.AmountToDeductFromTotal).ToString("N2") },
                    {"totalUsersPaid", tempFundsBeingPaid.Count.ToString()}};
                    EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN, RollinNewsConfig.DEFAULT_EMAIL_FROM_NAME, ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN, EmailServer.EmailServer.DEFAULT_SUBJECT_ROLLIN_NEWS + " Mass Pay Completed!", emailDataComplete, EmailServer.EmailServerLayoutsEnum.RNPaymentJustCompleted);

                    for (int i = 0; i < invoices.Count; i++)
                    {
                        Payment.PaymentGateway pg = new PaymentGateway();
                        pg.SetInvoiceStatus(invoices[i].InvoiceId, InvoiceStatus.Payment_Successful);
                    }
                }
                else
                {
                    SendErrorsOfMassPayToAdmins(output, massPayResponse);
                }


            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
        }
예제 #4
0
        //return RedirectToAction("Index", "Balance", new {message = 2});
        //return RedirectToAction("Index", "Balance", new {message = 1});
        public ActionResult Widthdraw()
        {
            var user = _userRepository.GetByUsername(User.Identity.Name);
            if(user.AvailableForWithdrawal < 5.0)
                throw new Exception("Invalid amount");

            var amountString = string.Format(CultureInfo.InvariantCulture, "{0:0.00}", user.AvailableForWithdrawal);
            var paypalConfig = new Dictionary<string, string>();
            paypalConfig.Add("apiUsername", "gigbucket_test7_api1.test.ru");
            paypalConfig.Add("apiPassword", "ANCAZ9WSDHPQ8Y8U");
            paypalConfig.Add("apiSignature", "AFcWxV21C7fd0v3bYYYRCpSSRl31A2cPmRQaJrQqtqnGQmQpAFCNohRs");
            paypalConfig.Add("mode", "sandbox");
            MassPayResponseType responseMassPayResponseType = new MassPayResponseType();
            try
            {
                MassPayReq massPay = new MassPayReq();

                List<MassPayRequestItemType> massPayItemList = new List<MassPayRequestItemType>();
                BasicAmountType amount = new BasicAmountType(CurrencyCodeType.USD, amountString);

                MassPayRequestItemType massPayRequestItem = new MassPayRequestItemType(amount);

                // Email Address of receiver
                massPayRequestItem.ReceiverEmail = user.Email;

                massPayItemList.Add(massPayRequestItem);
                MassPayRequestType massPayRequest = new MassPayRequestType(massPayItemList);
                massPay.MassPayRequest = massPayRequest;

                // Create the service wrapper object to make the API call
                PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(paypalConfig);
                // # API call
                // Invoke the massPay method in service wrapper object
                responseMassPayResponseType = service.MassPay(massPay, new SignatureCredential(paypalConfig["apiUsername"], paypalConfig["apiPassword"], paypalConfig["apiSignature"]));

                if (responseMassPayResponseType != null)
                {
                    // # Success values
                    if (responseMassPayResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                    {
                        var paymentTransaction = new PaymentTransaction
                        {
                            Amount = user.AvailableForWithdrawal,
                            CreateDate = DateTime.Now,
                            PaymentId = responseMassPayResponseType.Version,
                            Status = PaymentTransactionStatus.Success,
                            User = user,
                            PaymentAction = PaymentAction.Withdrawal,
                        };
                        _paymentTransactionRepository.Add(paymentTransaction);
                        user.Balance = user.Balance - user.AvailableForWithdrawal;
                        user.AvailableForWithdrawal = 0;
                        _userRepository.Update(user);
                        return RedirectToAction("Index", "Balance", new { message = 1 });
                    }
                    // # Error Values
                    else
                    {
                        var paymentTransaction = new PaymentTransaction
                        {
                            Amount = user.AvailableForWithdrawal,
                            CreateDate = DateTime.Now,
                            PaymentId = responseMassPayResponseType.Version,
                            Status = PaymentTransactionStatus.Failed,
                            User = user,
                            PaymentAction = PaymentAction.Withdrawal,
                        };
                        _paymentTransactionRepository.Add(paymentTransaction);
                        return RedirectToAction("Index", "Balance", new { message = 2 });
                    }
                }
            }
            // # Exception log
            catch (Exception ex)
            {
                var paymentTransaction = new PaymentTransaction
                {
                    Amount = user.AvailableForWithdrawal,
                    CreateDate = DateTime.Now,
                    PaymentId = "",
                    Status = PaymentTransactionStatus.Failed,
                    User = user,
                    PaymentAction = PaymentAction.Withdrawal,
                };
                _paymentTransactionRepository.Add(paymentTransaction);
                return RedirectToAction("Index", "Balance", new { message = 2 });
            }
            return RedirectToAction("Index", "Balance", new { message = 2 }); ;
        }