本文整理匯總了C#中PayPal.PayPalAPIInterfaceService.PayPalAPIInterfaceServiceService.DoDirectPayment方法的典型用法代碼示例。如果您正苦於以下問題:C# PayPalAPIInterfaceServiceService.DoDirectPayment方法的具體用法?C# PayPalAPIInterfaceServiceService.DoDirectPayment怎麽用?C# PayPalAPIInterfaceServiceService.DoDirectPayment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PayPal.PayPalAPIInterfaceService.PayPalAPIInterfaceServiceService
的用法示例。
在下文中一共展示了PayPalAPIInterfaceServiceService.DoDirectPayment方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Submit_Click
protected void Submit_Click(object sender, EventArgs e)
{
// 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), paymentType.SelectedValue);
// (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 = firstName.Value;
name.LastName = lastName.Value;
payer.PayerName = name;
// (Required) Details about the owner of the credit card.
creditCard.CardOwner = payer;
// (Required) Credit card number.
creditCard.CreditCardNumber = creditCardNumber.Value;
// (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), creditCardType.SelectedValue);
// 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 = cvv2Number.Value;
string[] cardExpiryDetails = cardExpiryDate.Text.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]);
}
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 = ipnNotificationUrl.Value.Trim();
// (Optional) Buyer's shipping address information.
AddressType billingAddr = new AddressType();
if (firstName.Value != string.Empty && lastName.Value != string.Empty
&& street1.Value != string.Empty && country.Value != string.Empty)
{
billingAddr.Name = payerName.Value;
// (Required) First street address.
billingAddr.Street1 = street1.Value;
// (Optional) Second street address.
billingAddr.Street2 = street2.Value;
// (Required) Name of city.
billingAddr.CityName = city.Value;
// (Required) State or province.
billingAddr.StateOrProvince = state.Value;
// (Required) Country code.
billingAddr.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), country.Value);
// (Required) U.S. ZIP code or other country-specific postal code.
billingAddr.PostalCode = postalCode.Value;
// (Optional) Phone number.
billingAddr.Phone = phone.Value;
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), currencyCode.SelectedValue);
BasicAmountType paymentAmount = new BasicAmountType(currency, amount.Value);
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]
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 DoDirectPayment method in service wrapper object
//.........這裏部分代碼省略.........
示例2: DoDirectPayment
private void DoDirectPayment(HttpContext context)
{
DoDirectPaymentReq req = new DoDirectPaymentReq();
req.DoDirectPaymentRequest = new DoDirectPaymentRequestType();
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType();
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType();
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType();
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress = new AddressType();
req.DoDirectPaymentRequest.Version = "78.0";
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = context.Request.Params["cardNum"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = (CreditCardTypeType)EnumUtils.getValue(context.Request.Params["creditcardType"], typeof(CreditCardTypeType));
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CVV2 = context.Request.Params["cvv2Num"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = System.Convert.ToInt32(context.Request.Params["expDateMonth"]);
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.ExpYear = System.Convert.ToInt32(context.Request.Params["expDateYear"]);
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentAction = (PaymentActionCodeType)EnumUtils.getValue(context.Request.Params["paymentType"], typeof(PaymentActionCodeType));
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = (CurrencyCodeType)EnumUtils.getValue(context.Request.Params["currencyCode"], typeof(CurrencyCodeType));
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.value = context.Request.Params["amount"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street1 = context.Request.Params["addr1"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street2 = context.Request.Params["addr2"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CityName = context.Request.Params["city"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.StateOrProvince = context.Request.Params["state"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.PostalCode = context.Request.Params["zipCode"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Country =(CountryCodeType)EnumUtils.getValue(context.Request.Params["countryCode"], typeof(CountryCodeType));
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Name = context.Request.Params["firstName"] + context.Request.Params["lastName"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner = new PayerInfoType();
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = new PersonNameType();
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerCountry = (CountryCodeType)EnumUtils.getValue(context.Request.Params["countryCode"], typeof(CountryCodeType));
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName=context.Request.Params["firstName"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = context.Request.Params["lastName"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address = new AddressType();
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 = context.Request.Params["addr1"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street2 = context.Request.Params["addr2"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = context.Request.Params["city"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince = context.Request.Params["state"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = context.Request.Params["zipCode"];
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country = (CountryCodeType)EnumUtils.getValue(context.Request.Params["countryCode"], typeof(CountryCodeType));
req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Name = context.Request.Params["firstName"] + context.Request.Params["lastName"];
try
{
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
DoDirectPaymentResponseType resp = service.DoDirectPayment(req);
context.Response.Write("<html><body><textarea rows=30 cols=80>");
ObjectDumper.Write(resp, 5, context.Response.Output);
context.Response.Write("</textarea></body></html>");
}
catch (System.Exception e)
{
context.Response.Write(e.Message);
}
}
示例3: Submit_Click
protected void Submit_Click(object sender, EventArgs e)
{
// Create request object
DoDirectPaymentRequestType request = new DoDirectPaymentRequestType();
DoDirectPaymentRequestDetailsType requestDetails = new DoDirectPaymentRequestDetailsType();
request.DoDirectPaymentRequestDetails = requestDetails;
requestDetails.PaymentAction = (PaymentActionCodeType)
Enum.Parse(typeof(PaymentActionCodeType), paymentType.SelectedValue);
// Populate card requestDetails
CreditCardDetailsType creditCard = new CreditCardDetailsType();
requestDetails.CreditCard = creditCard;
PayerInfoType payer = new PayerInfoType();
PersonNameType name = new PersonNameType();
name.FirstName = firstName.Value;
name.LastName = lastName.Value;
payer.PayerName = name;
creditCard.CardOwner = payer;
creditCard.CreditCardNumber = creditCardNumber.Value;
creditCard.CreditCardType = (CreditCardTypeType)
Enum.Parse(typeof(CreditCardTypeType), creditCardType.SelectedValue);
creditCard.CVV2 = cvv2Number.Value;
string[] cardExpiryDetails = cardExpiryDate.Text.Split(new char[] { '/' });
if (cardExpiryDetails.Length == 2)
{
creditCard.ExpMonth = Int32.Parse(cardExpiryDetails[0]);
creditCard.ExpYear = Int32.Parse(cardExpiryDetails[1]);
}
requestDetails.PaymentDetails = new PaymentDetailsType();
AddressType billingAddr = new AddressType();
if (firstName.Value != "" && lastName.Value != ""
&& street1.Value != "" && country.Value != "")
{
billingAddr.Name = payerName.Value;
billingAddr.Street1 = street1.Value;
billingAddr.Street2 = street2.Value;
billingAddr.CityName = city.Value;
billingAddr.StateOrProvince = state.Value;
billingAddr.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), country.Value);
billingAddr.PostalCode = postalCode.Value;
//Fix for release
billingAddr.Phone = phone.Value;
payer.Address = billingAddr;
}
// Populate payment requestDetails
CurrencyCodeType currency = (CurrencyCodeType)
Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue);
BasicAmountType paymentAmount = new BasicAmountType(currency, amount.Value);
requestDetails.PaymentDetails.OrderTotal = paymentAmount;
// Invoke the API
DoDirectPaymentReq wrapper = new DoDirectPaymentReq();
wrapper.DoDirectPaymentRequest = request;
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
DoDirectPaymentResponseType response = service.DoDirectPayment(wrapper);
// Check for API return status
setKeyResponseObjects(service, response);
}
示例4: DoDirectPaymentAPIOperation
// # DoDirectPaymentAPIOperation
// The MassPay API operation makes a payment to one or more PayPal account holders.
public DoDirectPaymentResponseType DoDirectPaymentAPIOperation()
{
// Create the DoDirectPaymentResponseType object
DoDirectPaymentResponseType responseDoDirectPaymentResponseType = new DoDirectPaymentResponseType();
try
{
// Create the DoDirectPaymentReq object
DoDirectPaymentReq doDirectPayment = new DoDirectPaymentReq();
DoDirectPaymentRequestDetailsType doDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();
// Information about the credit card to be charged.
CreditCardDetailsType creditCard = new CreditCardDetailsType();
// 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
// * Solo
// * Switch
// * 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.VISA;
// Credit Card number
creditCard.CreditCardNumber = "4770461107194023";
// ExpiryMonth of credit card
creditCard.ExpMonth = Convert.ToInt32("12");
// Expiry Year of credit card
creditCard.ExpYear = Convert.ToInt32("2021");
//Details about the owner of the credit card.
PayerInfoType cardOwner = new PayerInfoType();
// Email address of buyer.
cardOwner.Payer = "[email protected]";
creditCard.CardOwner = cardOwner;
doDirectPaymentRequestDetails.CreditCard = creditCard;
// Information about the payment
PaymentDetailsType paymentDetails = new PaymentDetailsType();
// IPN URL
// * PayPal Instant Payment Notification is a call back system that is initiated when a transaction is completed
// * The transaction related IPN variables will be received on the call back URL specified in the request
// * The IPN variables have to be sent back to the PayPal system for validation, upon validation PayPal will send a response string "VERIFIED" or "INVALID"
// * PayPal would continuously resend IPN if a wrong IPN is sent
paymentDetails.NotifyURL = "http://IPNhost";
// 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 sub-total of the order.
//
// If the transaction includes one or more one-time purchases, this field must be equal to
// the sum of the purchases. Set this field to 0 if the transaction does
// not include a one-time purchase such as when you set up a billing
// agreement for a recurring payment that is not immediately charged.
// When the field is set to 0, purchase-specific fields are ignored.
//
// * `Currency Code` - You must set the currencyID attribute to one of the
// 3-character currency codes for any of the supported PayPal
// currencies.
// * `Amount`
BasicAmountType orderTotal = new BasicAmountType(CurrencyCodeType.USD, "4.00");
paymentDetails.OrderTotal = orderTotal;
doDirectPaymentRequestDetails.PaymentDetails = paymentDetails;
// IP address of the buyer's browser.
// `Note:
// PayPal records this IP addresses as a means to detect possible fraud.`
doDirectPaymentRequestDetails.IPAddress = "127.0.0.1";
DoDirectPaymentRequestType doDirectPaymentRequest = new DoDirectPaymentRequestType(doDirectPaymentRequestDetails);
doDirectPayment.DoDirectPaymentRequest = doDirectPaymentRequest;
// Create the service wrapper object to make the API call
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
// # API call
// Invoke the DoDirectPayment method in service wrapper object
responseDoDirectPaymentResponseType = service.DoDirectPayment(doDirectPayment);
if (responseDoDirectPaymentResponseType != null)
{
// Response envelope acknowledgement
string acknowledgement = "DoDirectPayment API Operation - ";
acknowledgement += responseDoDirectPaymentResponseType.Ack.ToString();
//.........這裏部分代碼省略.........
示例5: AddressAndPayment
public ActionResult AddressAndPayment(FormCollection values)
{
// fill out basic info
var cart = ShoppingCartHelper.GetCart(HttpContext);
ViewData["cart"] = cart;
var deliveryLocation = LocationHelper.GetDeliveryLocation(HttpContext);
if (deliveryLocation == null)
{
deliveryLocation = db.University_Delivery.First(i => i.UniversityId == 1);
LocationHelper.SetDeliveryLocation(HttpContext, deliveryLocation);
}
ViewData["deliveryLocation"] = deliveryLocation;
DateTime deliveryTime;
if (deliveryLocation.DeliveryTime.Hour < DateTime.Now.Hour)
{
deliveryTime = DateTime.Now.Date.AddDays(1).AddHours(deliveryLocation.DeliveryTime.Hour);
}
else
{
deliveryTime = DateTime.Now.Date.AddHours(deliveryLocation.DeliveryTime.Hour);
}
ViewData["deliveryTime"] = deliveryTime;
var totalRewardPoints = db.Rewards.Sum(i => i.Amount);
ViewData["totalRewardPoints"] = totalRewardPoints;
//fillout order
var order = new Order();
var userId = MembershipHelper.GetUserIdByEmail(HttpContext.User.Identity.Name);
order.Gross = cart.Gross;
if (cart.CanUserRewardPoint)
{
order.rewardPoints = Convert.ToInt32(values["rewardPoints"]);
}
else
{
order.rewardPoints = 0;
}
order.Savings = order.rewardPoints / 100.0m;
order.Tax = 0.0m;
order.Fee = 0.0m;
order.billingFirstName = values["billingFirstName"];
order.billingLastName = values["billingLastName"];
order.billingAddress1 = values["billingAddress1"];
order.billingAddress2 = values["billingAddress2"];
order.billingCity = values["billingCity"];
order.billingState = values["billingState"];
order.billingZipCode = values["billingZipCode"];
order.PaymentType = (PaymentType)Enum.Parse(typeof(PaymentType), values["paymentType"]);
order.cardNumber = values["cardNumber"];
order.cardExpYear = int.Parse(values["cardExpYear"]);
order.cardExpMonth = int.Parse(values["cardExpMonth"]);
order.CSV = values["CSV"];
order.NeedDeliveryInfo = cart.NeedDeliveryInfo;
if (cart.NeedDeliveryInfo)
{
order.ReceiverFirstName = values["ReceiverFirstName"];
order.ReceiverLastName = values["ReceiverLastName"];
order.ReceiverPhoneNumber = values["ReceiverPhoneNumber"];
order.DeliveryTime = deliveryTime;
}
order.PayerEmail = HttpContext.User.Identity.Name;
order.UserId = userId.Value;
order.PayerEmail = User.Identity.Name;
order.OrderDescription = string.Join(",", cart.ShoppingCartItems.Select(i => i.Description).ToList());
order.DeliveryLocationId = deliveryLocation.LocationId;
PaymentStatusLevel paymentStatus = PaymentStatusLevel.WaitingForPayment;
DeliveryInfo deliveryInfo = new DeliveryInfo() { ReceiverFirstName = order.ReceiverFirstName, ReceiverLastName = order.ReceiverLastName };
if (!TryValidateModel(order))
{
return View("AddressAndPayment", "_CheckoutMaster", order);
}
else
{
if (order.PaymentType == PaymentType.CreditCard)
{
DoDirectPaymentRequestType request = new DoDirectPaymentRequestType();
DoDirectPaymentRequestDetailsType requestDetails = new DoDirectPaymentRequestDetailsType();
request.DoDirectPaymentRequestDetails = requestDetails;
requestDetails.PaymentAction = PaymentActionCodeType.SALE;
// Populate card requestDetails
CreditCardDetailsType creditCard = new CreditCardDetailsType();
requestDetails.CreditCard = creditCard;
PayerInfoType payer = new PayerInfoType();
PersonNameType name = new PersonNameType();
name.FirstName = order.billingFirstName;
name.LastName = order.billingLastName;
payer.PayerName = name;
creditCard.CardOwner = payer;
creditCard.CreditCardNumber = order.cardNumber;
creditCard.CreditCardType = (CreditCardTypeType)
Enum.Parse(typeof(CreditCardTypeType), values["creditCardType"]);
creditCard.CVV2 = order.CSV;
creditCard.ExpMonth = order.cardExpMonth;
creditCard.ExpYear = order.cardExpYear;
requestDetails.PaymentDetails = new PaymentDetailsType();
//.........這裏部分代碼省略.........