diff --git a/Yavsc/Controllers/ManageController.cs b/Yavsc/Controllers/ManageController.cs index fa71b0b5..3217646e 100644 --- a/Yavsc/Controllers/ManageController.cs +++ b/Yavsc/Controllers/ManageController.cs @@ -12,7 +12,6 @@ using Yavsc.ViewModels.Manage; using Microsoft.Extensions.OptionsModel; using Microsoft.Data.Entity; using System; -using PayPal.PayPalAPIInterfaceService; using System.Collections.Generic; using Yavsc.Helpers; using Yavsc.ViewModels.Calendar; @@ -24,7 +23,10 @@ using Yavsc.Models.Identity; namespace Yavsc.Controllers { using Models.Relationship; - + using PayPal.PayPalAPIInterfaceService; + using PayPal.PayPalAPIInterfaceService.Model; + using PayPal.PayPalAPIInterfaceService.Model; + [Authorize, ServiceFilter(typeof(LanguageActionFilter))] public class ManageController : Controller { @@ -605,16 +607,157 @@ namespace Yavsc.Controllers [HttpGet, Route("/Manage/Credits")] public IActionResult Credits() { - Dictionary config = new Dictionary(); + + return View(); + } + public Dictionary PaypalConfig {  + get {  + var config = + new Dictionary(); config.Add("mode", "sandbox"); config.Add("account1.apiUsername", _payPalSettings.UserId); config.Add("account1.apiPassword", _payPalSettings.Secret); config.Add("account1.apiSignature", _payPalSettings.Signature); - PayPalAPIInterfaceServiceService s = new PayPalAPIInterfaceServiceService(config); + return config; + } + } + + + protected IActionResult DoDirectCredit(DoDirectCreditViewModel model) + { + // Create request object + DoDirectPaymentRequestType request = new DoDirectPaymentRequestType(); + DoDirectPaymentRequestDetailsType requestDetails = new DoDirectPaymentRequestDetailsType(); + request.DoDirectPaymentRequestDetails = requestDetails; + + // (Optional) How you want to obtain payment. It is one of the following values: + // * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture. + // * Sale – This is a final sale for which you are requesting payment (default). + // Note: Order is not allowed for Direct Payment. + requestDetails.PaymentAction = (PaymentActionCodeType) + Enum.Parse(typeof(PaymentActionCodeType), model.PaymentType); + + // (Required) Information about the credit card to be charged. + CreditCardDetailsType creditCard = new CreditCardDetailsType(); + requestDetails.CreditCard = creditCard; + PayerInfoType payer = new PayerInfoType(); + // (Optional) First and last name of buyer. + PersonNameType name = new PersonNameType(); + name.FirstName = model.FirstName; + name.LastName = model.LastName; + payer.PayerName = name; + // (Required) Details about the owner of the credit card. + creditCard.CardOwner = payer; + + // (Required) Credit card number. + creditCard.CreditCardNumber = model.CreditCardNumber; + // (Optional) Type of credit card. For UK, only Maestro, MasterCard, Discover, and Visa are allowable. For Canada, only MasterCard and Visa are allowable and Interac debit cards are not supported. It is one of the following values: + // * Visa + // * MasterCard + // * Discover + // * Amex + // * Maestro: See note. + // Note: If the credit card type is Maestro, you must set currencyId to GBP. In addition, you must specify either StartMonth and StartYear or IssueNumber. + creditCard.CreditCardType = (CreditCardTypeType) + Enum.Parse(typeof(CreditCardTypeType), model.CreditCardType); + // Card Verification Value, version 2. Your Merchant Account settings determine whether this field is required. To comply with credit card processing regulations, you must not store this value after a transaction has been completed. + // Character length and limitations: For Visa, MasterCard, and Discover, the value is exactly 3 digits. For American Express, the value is exactly 4 digits. + creditCard.CVV2 = model.Cvv2Number; + string[] cardExpiryDetails = model.CardExpiryDate.Split(new char[] { '/' }); + if (cardExpiryDetails.Length == 2) + { + // (Required) Credit card expiration month. + creditCard.ExpMonth = Convert.ToInt32(cardExpiryDetails[0]); + // (Required) Credit card expiration year. + creditCard.ExpYear = Convert.ToInt32(cardExpiryDetails[1]); + } - return View(); + requestDetails.PaymentDetails = new PaymentDetailsType(); + // (Optional) Your URL for receiving Instant Payment Notification (IPN) about this transaction. If you do not specify this value in the request, the notification URL from your Merchant Profile is used, if one exists. + // Important: The notify URL applies only to DoExpressCheckoutPayment. This value is ignored when set in SetExpressCheckout or GetExpressCheckoutDetails. + requestDetails.PaymentDetails.NotifyURL = model.IpnNotificationUrl.Trim(); + + // (Optional) Buyer's shipping address information. + AddressType billingAddr = new AddressType(); + if (model.FirstName != string.Empty && model.LastName != string.Empty + && model.Street1 != string.Empty && model.Country != string.Empty) + { + billingAddr.Name = model.PayerName; + // (Required) First street address. + billingAddr.Street1 = model.Street1; + // (Optional) Second street address. + billingAddr.Street2 = model.Street2; + // (Required) Name of city. + billingAddr.CityName = model.City; + // (Required) State or province. + billingAddr.StateOrProvince = model.State; + // (Required) Country code. + billingAddr.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), model.Country); + // (Required) U.S. ZIP code or other country-specific postal code. + billingAddr.PostalCode = model.PostalCode; + + // (Optional) Phone number. + billingAddr.Phone = model.Phone; + + payer.Address = billingAddr; + } + + // (Required) The total cost of the transaction to the buyer. If shipping cost and tax charges are known, include them in this value. If not, this value should be the current subtotal of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. This field must be set to a value greater than 0. + // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies. + CurrencyCodeType currency = (CurrencyCodeType) + Enum.Parse(typeof(CurrencyCodeType), model.CurrencyCode); + BasicAmountType paymentAmount = new BasicAmountType(currency, model.Amount); + requestDetails.PaymentDetails.OrderTotal = paymentAmount; + + // Invoke the API + DoDirectPaymentReq wrapper = new DoDirectPaymentReq(); + wrapper.DoDirectPaymentRequest = 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] + //// TODO clean Dictionary configurationMap = Configuration.GetAcctAndConfig(); + + // Create the PayPalAPIInterfaceServiceService service object to make the API call + PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(PaypalConfig); + + // # API call + // Invoke the DoDirectPayment method in service wrapper object + DoDirectPaymentResponseType response = service.DoDirectPayment(wrapper); + + // Check for API return status + return setKeyResponseObjects(service, response); } + private IActionResult setKeyResponseObjects(PayPalAPIInterfaceServiceService service, DoDirectPaymentResponseType response) + { + HttpContext.Items.Add("Response_apiName", "DoDirectPayment"); + HttpContext.Items.Add("Response_redirectURL", null); + HttpContext.Items.Add("Response_requestPayload", service.getLastRequest()); + HttpContext.Items.Add("Response_responsePayload", service.getLastResponse()); + + Dictionary responseParams = new Dictionary(); + responseParams.Add("Correlation Id", response.CorrelationID); + responseParams.Add("API Result", response.Ack.ToString()); + + if (response.Ack.Equals(AckCodeType.FAILURE) || + (response.Errors != null && response.Errors.Count > 0)) + { + HttpContext.Items.Add("Response_error", response.Errors); + } + else + { + HttpContext.Items.Add("Response_error", null); + responseParams.Add("Transaction Id", response.TransactionID); + responseParams.Add("Payment status", response.PaymentStatus.ToString()); + if(response.PendingReason != null) { + responseParams.Add("Pending reason", response.PendingReason.ToString()); + } + } + HttpContext.Items.Add("Response_keyResponseObject", responseParams); + return View("APIResponse"); + } + #region Helpers private void AddErrors(IdentityResult result) diff --git a/Yavsc/ViewModels/Manage/DoDirectCreditViewModel.cs b/Yavsc/ViewModels/Manage/DoDirectCreditViewModel.cs new file mode 100644 index 00000000..c6c601e4 --- /dev/null +++ b/Yavsc/ViewModels/Manage/DoDirectCreditViewModel.cs @@ -0,0 +1,24 @@ +namespace Yavsc.ViewModels.Manage +{ + + public class DoDirectCreditViewModel { + public string PaymentType  { get; set;} + public string PayerName  { get; set;} + public string FirstName  { get; set;} + public string LastName  { get; set;} + public string CreditCardNumber  { get; set;} + public string CreditCardType  { get; set;} + public string Cvv2Number  { get; set;} + public string CardExpiryDate  { get; set;} + public string IpnNotificationUrl { get; set; } + public string Street1 { get; set; } + public string Street2 { get; set; } + public string City { get; set; } + public string State { get; set; } + public string Country { get; set; } + public string PostalCode { get; set; } + public string Phone { get; set; } + public string CurrencyCode { get; set; } + public string Amount { get; set; } + } +} \ No newline at end of file diff --git a/Yavsc/Views/Manage/Credits.cshtml b/Yavsc/Views/Manage/Credits.cshtml index 3adb63f5..935f61cf 100755 --- a/Yavsc/Views/Manage/Credits.cshtml +++ b/Yavsc/Views/Manage/Credits.cshtml @@ -4,12 +4,43 @@

@ViewData["Title"]

Your credits + PAYMENTS BY PayPal +
+ +
+
+
+ Buyer's Email address *
+
+ +
+
+ First line of street address *
+
+ +
+
+ Postal code *
+
+ +
+
+ +
+
+ Home  Backz +
+
+

- - - diff --git a/Yavsc/Views/Manage/DoDirectCredit.cshtml b/Yavsc/Views/Manage/DoDirectCredit.cshtml new file mode 100644 index 00000000..e69de29b diff --git a/Yavsc/project.json b/Yavsc/project.json index 86b0891d..2ee7e28d 100755 --- a/Yavsc/project.json +++ b/Yavsc/project.json @@ -102,13 +102,13 @@ "Microsoft.AspNet.DataProtection.SystemWeb": "1.0.0-rc1-final", "Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-rc1-final", "PayPalCoreSDK": "1.7.1", - "PayPalButtonManagerSDK": "2.10.109", "Microsoft.AspNet.Authentication.OAuth": "1.0.0-rc1-final", "Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-rc1-final", "Microsoft.AspNet.OWin": "1.0.0-rc1-final", "System.Json": "4.0.20126.16343", "YavscLib": "1.0.0-*", - "Extensions.AspNet.Authentication.Instagram": "1.0.0-t150809211713" + "Extensions.AspNet.Authentication.Instagram": "1.0.0-t150809211713", + "PayPalMerchantSDK": "2.16.204" }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000", diff --git a/Yavsc/project.lock.json b/Yavsc/project.lock.json index 8734d26f..c380187f 100644 --- a/Yavsc/project.lock.json +++ b/Yavsc/project.lock.json @@ -2523,28 +2523,28 @@ "lib/net40/Owin.dll": {} } }, - "PayPalButtonManagerSDK/2.10.109": { + "PayPalCoreSDK/1.7.1": { "type": "package", "dependencies": { - "PayPalCoreSDK": "1.7.0" + "Newtonsoft.Json": "7.0.1" }, "compile": { - "lib/net20/PayPalButtonManagerSDK.dll": {} + "lib/net451/PayPalCoreSDK.dll": {} }, "runtime": { - "lib/net20/PayPalButtonManagerSDK.dll": {} + "lib/net451/PayPalCoreSDK.dll": {} } }, - "PayPalCoreSDK/1.7.1": { + "PayPalMerchantSDK/2.16.204": { "type": "package", "dependencies": { - "Newtonsoft.Json": "7.0.1" + "PayPalCoreSDK": "1.7.1" }, "compile": { - "lib/net451/PayPalCoreSDK.dll": {} + "lib/net20/PayPalMerchantSDK.dll": {} }, "runtime": { - "lib/net451/PayPalCoreSDK.dll": {} + "lib/net20/PayPalMerchantSDK.dll": {} } }, "Remotion.Linq/2.0.1": { @@ -5362,28 +5362,28 @@ "lib/net40/Owin.dll": {} } }, - "PayPalButtonManagerSDK/2.10.109": { + "PayPalCoreSDK/1.7.1": { "type": "package", "dependencies": { - "PayPalCoreSDK": "1.7.0" + "Newtonsoft.Json": "7.0.1" }, "compile": { - "lib/net20/PayPalButtonManagerSDK.dll": {} + "lib/net451/PayPalCoreSDK.dll": {} }, "runtime": { - "lib/net20/PayPalButtonManagerSDK.dll": {} + "lib/net451/PayPalCoreSDK.dll": {} } }, - "PayPalCoreSDK/1.7.1": { + "PayPalMerchantSDK/2.16.204": { "type": "package", "dependencies": { - "Newtonsoft.Json": "7.0.1" + "PayPalCoreSDK": "1.7.1" }, "compile": { - "lib/net451/PayPalCoreSDK.dll": {} + "lib/net20/PayPalMerchantSDK.dll": {} }, "runtime": { - "lib/net451/PayPalCoreSDK.dll": {} + "lib/net20/PayPalMerchantSDK.dll": {} } }, "Remotion.Linq/2.0.1": { @@ -8201,28 +8201,28 @@ "lib/net40/Owin.dll": {} } }, - "PayPalButtonManagerSDK/2.10.109": { + "PayPalCoreSDK/1.7.1": { "type": "package", "dependencies": { - "PayPalCoreSDK": "1.7.0" + "Newtonsoft.Json": "7.0.1" }, "compile": { - "lib/net20/PayPalButtonManagerSDK.dll": {} + "lib/net451/PayPalCoreSDK.dll": {} }, "runtime": { - "lib/net20/PayPalButtonManagerSDK.dll": {} + "lib/net451/PayPalCoreSDK.dll": {} } }, - "PayPalCoreSDK/1.7.1": { + "PayPalMerchantSDK/2.16.204": { "type": "package", "dependencies": { - "Newtonsoft.Json": "7.0.1" + "PayPalCoreSDK": "1.7.1" }, "compile": { - "lib/net451/PayPalCoreSDK.dll": {} + "lib/net20/PayPalMerchantSDK.dll": {} }, "runtime": { - "lib/net451/PayPalCoreSDK.dll": {} + "lib/net20/PayPalMerchantSDK.dll": {} } }, "Remotion.Linq/2.0.1": { @@ -10570,16 +10570,6 @@ "Owin.nuspec" ] }, - "PayPalButtonManagerSDK/2.10.109": { - "type": "package", - "sha512": "6l95DlflMld+OmzOGaw3T6Mb9rZrywO1pR8jbafyvu34FId4osC1oo5RfgQVY0rwHkeTG359U+X3BPL6vVRT8Q==", - "files": [ - "lib/net20/PayPalButtonManagerSDK.dll", - "PayPalButtonManagerSDK.2.10.109.nupkg", - "PayPalButtonManagerSDK.2.10.109.nupkg.sha512", - "PayPalButtonManagerSDK.nuspec" - ] - }, "PayPalCoreSDK/1.7.1": { "type": "package", "sha512": "hGOLo3X2vgOpOWJI91+vlBgr/Dchk3xZAF0bdIpKiAwjlRKMjzSC4zuT1eGwmQ8uVL1IaGBZwNGklyRHDniYlQ==", @@ -10594,6 +10584,17 @@ "PayPalCoreSDK.nuspec" ] }, + "PayPalMerchantSDK/2.16.204": { + "type": "package", + "sha512": "uqn99kb71EYWbdYz3dIXTeTzbh5buhfa7uvSemZXDFW1BRnDi8CGAdbK2AX7ZT1JsH3GuQZqxqC0/KpWKML9Wg==", + "files": [ + "lib/net20/PayPalMerchantSDK.dll", + "lib/net20/PayPalMerchantSDK.xml", + "PayPalMerchantSDK.2.16.204.nupkg", + "PayPalMerchantSDK.2.16.204.nupkg.sha512", + "PayPalMerchantSDK.nuspec" + ] + }, "Remotion.Linq/2.0.1": { "type": "package", "sha512": "SIO6HDH6CU9GC2IZGBrc6q5X5vRhfatXrg9cVavCEG9W6v5e88b+vXjmLGQEorch4sYEIImRr+ODyUMyrmrqAg==", @@ -11499,13 +11500,13 @@ "Microsoft.AspNet.DataProtection.SystemWeb >= 1.0.0-rc1-final", "Microsoft.AspNet.Authentication.JwtBearer >= 1.0.0-rc1-final", "PayPalCoreSDK >= 1.7.1", - "PayPalButtonManagerSDK >= 2.10.109", "Microsoft.AspNet.Authentication.OAuth >= 1.0.0-rc1-final", "Microsoft.AspNet.Mvc.Formatters.Json >= 6.0.0-rc1-final", "Microsoft.AspNet.OWin >= 1.0.0-rc1-final", "System.Json >= 4.0.20126.16343", "YavscLib >= 1.0.0-*", - "Extensions.AspNet.Authentication.Instagram >= 1.0.0-t150809211713" + "Extensions.AspNet.Authentication.Instagram >= 1.0.0-t150809211713", + "PayPalMerchantSDK >= 2.16.204" ], "DNX,Version=v4.5.1": [ "fx/System.Drawing >= 4.0.0"