本文整理汇总了C#中PayPal.PayPalAPIInterfaceService.Model.BasicAmountType类的典型用法代码示例。如果您正苦于以下问题:C# BasicAmountType类的具体用法?C# BasicAmountType怎么用?C# BasicAmountType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicAmountType类属于PayPal.PayPalAPIInterfaceService.Model命名空间,在下文中一共展示了BasicAmountType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search_Submit
protected void Search_Submit(object sender, EventArgs e)
{
// Create request object
TransactionSearchRequestType request = new TransactionSearchRequestType();
if (transactionID.Value != "")
{
request.TransactionID = transactionID.Value;
}
if (startDate != null && startDate.Text != null)
{
request.StartDate = startDate.Text;
}
if (endDate != null && endDate.Text != null)
{
request.EndDate = endDate.Text;
}
if (payer.Value != "")
{
request.Payer = payer.Value;
}
if (receiver.Value != "")
{
request.Receiver = receiver.Value;
}
if (receiptId.Value != "")
{
request.ReceiptID = receiptId.Value;
}
if (profileId.Value != "")
{
request.ProfileID = profileId.Value;
}
if (auctionItemNumber.Value != "")
{
request.AuctionItemNumber = auctionItemNumber.Value;
}
if (invoiceID.Value != "")
{
request.InvoiceID = invoiceID.Value;
}
if (cardNumber.Value != "")
{
request.CardNumber = cardNumber.Value;
}
if (transactionClass.SelectedIndex != 0)
{
request.TransactionClass = (PaymentTransactionClassCodeType)
Enum.Parse(typeof(PaymentTransactionClassCodeType), transactionClass.SelectedValue);
}
if (amount.Value != "" && currencyCode.SelectedIndex != 0)
{
request.CurrencyCode = (CurrencyCodeType)
Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue);
BasicAmountType searchAmount = new BasicAmountType(request.CurrencyCode, amount.Value);
request.Amount = searchAmount;
}
if (transactionStatus.SelectedIndex != 0)
{
request.Status = (PaymentTransactionStatusCodeType)
Enum.Parse(typeof(PaymentTransactionStatusCodeType), transactionStatus.SelectedValue);
}
// Invoke the API
TransactionSearchReq wrapper = new TransactionSearchReq();
wrapper.TransactionSearchRequest = request;
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
TransactionSearchResponseType transactionDetails = service.TransactionSearch(wrapper);
// Check for API return status
processResponse(service, transactionDetails);
}
示例2: DoAuthorization
// <summary>
/// Handles DoAuthorization
/// </summary>
/// <param name="contextHttp"></param>
private void DoAuthorization(HttpContext contextHttp)
{
NameValueCollection parameters = contextHttp.Request.Params;
// 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();
// Creating service wrapper object to make an API call by loading configuration map.
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
DoAuthorizationReq req = new DoAuthorizationReq();
// 'Amount' which takes mandatory params:
// * 'currencyCode'
// * 'amount'
BasicAmountType amount = new BasicAmountType(((CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), parameters["currencyCode"])), parameters["amt"]);
// 'DoAuthorizationRequest' which takes mandatory params:
// * 'Transaction ID' - Value of the order's transaction identification
// number returned by PayPal.
// * 'Amount' - Amount to authorize.
DoAuthorizationRequestType reqType = new DoAuthorizationRequestType(parameters["authID"], amount);
req.DoAuthorizationRequest = reqType;
DoAuthorizationResponseType response = null;
try
{
response = service.DoAuthorization(req);
}
catch (System.Exception ex)
{
contextHttp.Response.Write(ex.StackTrace);
return;
}
Dictionary<string, string> responseValues = new Dictionary<string, string>();
string redirectUrl = null;
if (!response.Ack.ToString().Trim().ToUpper().Equals(AckCode.FAILURE.ToString()) && !response.Ack.ToString().Trim().ToUpper().Equals(AckCode.FAILUREWITHWARNING.ToString()))
{
responseValues.Add("Acknowledgement", response.Ack.ToString().Trim().ToUpper());
responseValues.Add("TransactionId", response.TransactionID);
}
else
{
responseValues.Add("Acknowledgement", response.Ack.ToString().Trim().ToUpper());
}
Display(contextHttp, "DoAuthorization", "DoAuthorization", responseValues, service.getLastRequest(), service.getLastResponse(), response.Errors, redirectUrl);
}
示例3: SetMobileCheckoutRequestDetailsType
/// <summary>
/// Constructor with arguments
/// </summary>
public SetMobileCheckoutRequestDetailsType(BasicAmountType itemAmount, string itemName, string returnURL)
{
this.ItemAmount = itemAmount;
this.ItemName = itemName;
this.ReturnURL = returnURL;
}
示例4: ActivationDetailsType
/// <summary>
/// Constructor with arguments
/// </summary>
public ActivationDetailsType(BasicAmountType initialAmount)
{
this.InitialAmount = initialAmount;
}
示例5: DoReauthorizationRequestType
/// <summary>
/// Constructor with arguments
/// </summary>
public DoReauthorizationRequestType(string authorizationID, BasicAmountType amount)
{
this.AuthorizationID = authorizationID;
this.Amount = amount;
}
示例6: DoAuthorizationRequestType
/// <summary>
/// Constructor with arguments
/// </summary>
public DoAuthorizationRequestType(string transactionID, BasicAmountType amount)
{
this.TransactionID = transactionID;
this.Amount = amount;
}
示例7: 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
//.........这里部分代码省略.........
示例8: DoExpressCheckoutPayment
// # DoExpressCheckoutPayment API Operation
// The DoExpressCheckoutPayment API operation completes an Express Checkout transaction.
// If you set up a billing agreement in your SetExpressCheckout API call,
// the billing agreement is created when you call the DoExpressCheckoutPayment API operation.
public DoExpressCheckoutPaymentResponseType DoExpressCheckoutPayment(string token, string payerId, string payment)
{
// Create the DoExpressCheckoutPaymentResponseType object
DoExpressCheckoutPaymentResponseType responseDoExpressCheckoutPaymentResponseType = new DoExpressCheckoutPaymentResponseType();
try
{
// Create the DoExpressCheckoutPaymentReq object
DoExpressCheckoutPaymentReq doExpressCheckoutPayment = new DoExpressCheckoutPaymentReq();
DoExpressCheckoutPaymentRequestDetailsType doExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
// The timestamped token value that was returned in the
// `SetExpressCheckout` response and passed in the
// `GetExpressCheckoutDetails` request.
doExpressCheckoutPaymentRequestDetails.Token = token;
// Unique paypal buyer account identification number as returned in
// `GetExpressCheckoutDetails` Response
doExpressCheckoutPaymentRequestDetails.PayerID = payerId;
// # Payment Information
// list of information about the payment
List<PaymentDetailsType> paymentDetailsList = new List<PaymentDetailsType>();
// information about the first payment
PaymentDetailsType paymentDetails1 = new PaymentDetailsType();
// 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 orderTotal1 = new BasicAmountType(CurrencyCodeType.USD, payment);
paymentDetails1.OrderTotal = orderTotal1;
paymentDetails1.OrderDescription = System.Web.Configuration.WebConfigurationManager.AppSettings["PaypalDescription"];
// How you want to obtain payment. When implementing parallel payments,
// this field is required and must be set to `Order`. When implementing
// digital goods, this field is required and must be set to `Sale`. If the
// transaction does not include a one-time purchase, this field is
// ignored. It is one of the following values:
//
// * `Sale` - This is a final sale for which you are requesting payment
// (default).
// * `Authorization` - This payment is a basic authorization subject to
// settlement with PayPal Authorization and Capture.
// * `Order` - This payment is an order authorization subject to
// settlement with PayPal Authorization and Capture.
// Note:
// You cannot set this field to Sale in SetExpressCheckout request and
// then change the value to Authorization or Order in the
// DoExpressCheckoutPayment request. If you set the field to
// Authorization or Order in SetExpressCheckout, you may set the field
// to Sale.
paymentDetails1.PaymentAction = PaymentActionCodeType.SALE;
// Unique identifier for the merchant. For parallel payments, this field
// is required and must contain the Payer Id or the email address of the
// merchant.
SellerDetailsType sellerDetails1 = new SellerDetailsType();
sellerDetails1.PayPalAccountID = System.Web.Configuration.WebConfigurationManager.AppSettings["PayPalAccountID"];
paymentDetails1.SellerDetails = sellerDetails1;
// A unique identifier of the specific payment request, which is
// required for parallel payments.
paymentDetails1.PaymentRequestID = "PaymentRequest1";
// A unique identifier of the specific payment request, which is
// required for parallel payments.
paymentDetailsList.Add(paymentDetails1);
doExpressCheckoutPaymentRequestDetails.PaymentDetails = paymentDetailsList;
DoExpressCheckoutPaymentRequestType doExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType(doExpressCheckoutPaymentRequestDetails);
doExpressCheckoutPayment.DoExpressCheckoutPaymentRequest = doExpressCheckoutPaymentRequest;
// Create the service wrapper object to make the API call
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
// # API call
// Invoke the DoExpressCheckoutPayment method in service wrapper object
responseDoExpressCheckoutPaymentResponseType = service.DoExpressCheckoutPayment(doExpressCheckoutPayment);
return responseDoExpressCheckoutPaymentResponseType;
}
// # Exception log
catch (System.Exception ex)
//.........这里部分代码省略.........
示例9: 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();
//.........这里部分代码省略.........
示例10: populateRequest
private void populateRequest(CreateRecurringPaymentsProfileRequestType request)
{
CurrencyCodeType currency = (CurrencyCodeType)
Enum.Parse(typeof(CurrencyCodeType), "USD");
// Set EC-Token or Credit card requestDetails
CreateRecurringPaymentsProfileRequestDetailsType profileDetails = new CreateRecurringPaymentsProfileRequestDetailsType();
request.CreateRecurringPaymentsProfileRequestDetails = profileDetails;
// A timestamped token, the value of which was returned in the response to the first call to SetExpressCheckout. You can also use the token returned in the SetCustomerBillingAgreement response. Either this token or a credit card number is required. If you include both token and credit card number, the token is used and credit card number is ignored Call CreateRecurringPaymentsProfile once for each billing agreement included in SetExpressCheckout request and use the same token for each call. Each CreateRecurringPaymentsProfile request creates a single recurring payments profile.
// Note: Tokens expire after approximately 3 hours.
if(token.Value != string.Empty)
{
profileDetails.Token = token.Value;
}
// Credit card information for recurring payments using direct payments. Either a token or a credit card number is required. If you include both token and credit card number, the token is used and credit card number is ignored.
else if (creditCardNumber.Value != string.Empty && cvv.Value != string.Empty)
{
CreditCardDetailsType cc = new CreditCardDetailsType();
// (Required) Credit card number.
cc.CreditCardNumber = creditCardNumber.Value;
// 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.
cc.CVV2 = cvv.Value;
// (Required) Credit card expiration month.
cc.ExpMonth = Convert.ToInt32(expMonth.SelectedValue);
// (Required) Credit card expiration year.
cc.ExpYear = Convert.ToInt32(expYear.SelectedValue);
profileDetails.CreditCard = cc;
}
// Populate Recurring Payments Profile Details
RecurringPaymentsProfileDetailsType rpProfileDetails =
new RecurringPaymentsProfileDetailsType(billingStartDate.Text);
profileDetails.RecurringPaymentsProfileDetails = rpProfileDetails;
// (Optional) Full name of the person receiving the product or service paid for by the recurring payment. If not present, the name in the buyer's PayPal account is used.
if(subscriberName.Value != string.Empty)
{
rpProfileDetails.SubscriberName = subscriberName.Value;
}
// (Optional) The subscriber's shipping address associated with this profile, if applicable. If not specified, the ship-to address from buyer's PayPal account is used.
if(shippingName.Value != string.Empty && shippingStreet1.Value != string.Empty && shippingCity.Value != string.Empty
&& shippingState.Value != string.Empty && shippingPostalCode.Value != string.Empty && shippingCountry.Value != string.Empty)
{
AddressType shippingAddr = new AddressType();
// Person's name associated with this shipping address. It is required if using a shipping address.
shippingAddr.Name = shippingName.Value;
// First street address. It is required if using a shipping address.
shippingAddr.Street1 = shippingStreet1.Value;
// Name of city. It is required if using a shipping address.
shippingAddr.CityName = shippingCity.Value;
// State or province. It is required if using a shipping address.
shippingAddr.StateOrProvince = shippingState.Value;
// Country code. It is required if using a shipping address.
shippingAddr.CountryName = shippingCountry.Value;
// U.S. ZIP code or other country-specific postal code. It is required if using a U.S. shipping address; may be required for other countries.
shippingAddr.PostalCode = shippingPostalCode.Value;
// (Optional) Second street address.
if(shippingStreet2.Value != string.Empty)
{
shippingAddr.Street2 = shippingStreet2.Value;
}
// (Optional) Phone number.
if(shippingPhone.Value != string.Empty)
{
shippingAddr.Phone = shippingPhone.Value;
}
rpProfileDetails.SubscriberShippingAddress = shippingAddr;
}
// (Required) Describes the recurring payments schedule, including the regular payment period, whether there is a trial period, and the number of payments that can fail before a profile is suspended.
ScheduleDetailsType scheduleDetails = new ScheduleDetailsType();
// (Required) Description of the recurring payment.
// Note: You must ensure that this field matches the corresponding billing agreement description included in the SetExpressCheckout request.
if(profileDescription.Value != string.Empty)
{
scheduleDetails.Description = profileDescription.Value;
}
// (Optional) Number of scheduled payments that can fail before the profile is automatically suspended. An IPN message is sent to the merchant when the specified number of failed payments is reached.
if(maxFailedPayments.Value != string.Empty)
{
scheduleDetails.MaxFailedPayments = Convert.ToInt32(maxFailedPayments.Value);
}
// (Optional) Indicates whether you would like PayPal to automatically bill the outstanding balance amount in the next billing cycle. The outstanding balance is the total amount of any previously failed scheduled payments that have yet to be successfully paid. It is one of the following values:
// * NoAutoBill – PayPal does not automatically bill the outstanding balance.
// * AddToNextBilling – PayPal automatically bills the outstanding balance.
if(autoBillOutstandingAmount.SelectedIndex != 0)
{
scheduleDetails.AutoBillOutstandingAmount = (AutoBillType)
Enum.Parse(typeof(AutoBillType), autoBillOutstandingAmount.SelectedValue);
}
// (Optional) Information about activating a profile, such as whether there is an initial non-recurring payment amount immediately due upon profile creation and how to override a pending profile PayPal suspends when the initial payment amount fails.
if(initialAmount.Value != string.Empty)
{
// (Optional) Initial non-recurring payment amount due immediately upon profile creation. Use an initial amount for enrolment or set-up fees.
// Note: All amounts included in the request must have the same currency.
ActivationDetailsType activationDetails =
new ActivationDetailsType(new BasicAmountType(currency, initialAmount.Value));
// (Optional) Action you can specify when a payment fails. It is one of the following values:
// * ContinueOnFailure – By default, PayPal suspends the pending profile in the event that the initial payment amount fails. You can override this default behavior by setting this field to ContinueOnFailure. Then, if the initial payment amount fails, PayPal adds the failed payment amount to the outstanding balance for this recurring payment profile.
//.........这里部分代码省略.........
示例11: SetExpressCheckoutForRecurringPayments
/// <summary>
/// Handles Set Express Checkout For Recurring Payments
/// </summary>
/// <param name="contextHttp"></param>
private void SetExpressCheckoutForRecurringPayments(HttpContext contextHttp)
{
NameValueCollection parameters = contextHttp.Request.Params;
// 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);
SetExpressCheckoutRequestType setExpressCheckoutReq = new SetExpressCheckoutRequestType();
SetExpressCheckoutRequestDetailsType details = new SetExpressCheckoutRequestDetailsType();
string requestUrl = ConfigurationManager.AppSettings["HOSTING_ENDPOINT"].ToString();
// (Required) URL to which the buyer's browser is returned after choosing to pay with PayPal. For digital goods, you must add JavaScript to this page to close the in-context experience.
// Note:
// PayPal recommends that the value be the final review page on which the buyer confirms the order and payment or billing agreement.
UriBuilder uriBuilder = new UriBuilder(requestUrl);
uriBuilder.Path = contextHttp.Request.ApplicationPath
+ (contextHttp.Request.ApplicationPath.EndsWith("/") ? string.Empty : "/")
+ "UseCaseSamples/SetExpressCheckoutForRecurringPayments.aspx";
string returnUrl = uriBuilder.Uri.ToString();
// (Required) URL to which the buyer is returned if the buyer does not approve the use of PayPal to pay you. For digital goods, you must add JavaScript to this page to close the in-context experience.
// Note:
// PayPal recommends that the value be the original page on which the buyer chose to pay with PayPal or establish a billing agreement.
uriBuilder = new UriBuilder(requestUrl);
uriBuilder.Path = contextHttp.Request.ApplicationPath
+ (contextHttp.Request.ApplicationPath.EndsWith("/") ? string.Empty : "/")
+ "UseCaseSamples/SetExpressCheckoutForRecurringPayments.aspx";
string cancelUrl = uriBuilder.Uri.ToString();
// (Required) URL to which the buyer's browser is returned after choosing
// to pay with PayPal. For digital goods, you must add JavaScript to this
// page to close the in-context experience.
// Note:
// PayPal recommends that the value be the final review page on which the buyer
// confirms the order and payment or billing agreement.
// Character length and limitations: 2048 single-byte characters
details.ReturnURL = returnUrl + "?currencyCodeType=" + parameters["currencyCode"];
details.CancelURL = cancelUrl;
// (Optional) Email address of the buyer as entered during checkout.
// PayPal uses this value to pre-fill the PayPal membership sign-up portion on the PayPal pages.
// Character length and limitations: 127 single-byte alphanumeric characters
details.BuyerEmail = parameters["buyerMail"];
decimal itemTotal = 0.0M;
decimal orderTotal = 0.0M;
// Cost of item. This field is required when you pass a value for ItemCategory.
string amountItems = parameters["itemAmount"];
// Item quantity. This field is required when you pass a value for ItemCategory.
// For digital goods (ItemCategory=Digital), this field is required.
// Character length and limitations: Any positive integer
string qtyItems = parameters["itemQuantity"];
// Item name. This field is required when you pass a value for ItemCategory.
// Character length and limitations: 127 single-byte characters
string names = parameters["itemName"];
List<PaymentDetailsItemType> lineItems = new List<PaymentDetailsItemType>();
PaymentDetailsItemType item = new PaymentDetailsItemType();
BasicAmountType amt = new BasicAmountType();
// PayPal uses 3-character ISO-4217 codes for specifying currencies in fields and variables.
amt.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), parameters["currencyCode"]);
amt.value = amountItems;
item.Quantity = Convert.ToInt32(qtyItems);
item.Name = names;
item.Amount = amt;
// Indicates whether an item is digital or physical. For digital goods, this field is required and must be set to Digital. It is one of the following values:
// 1. Digital
// 2. Physical
item.ItemCategory = (ItemCategoryType)Enum.Parse(typeof(ItemCategoryType), parameters["itemCategory"]);
// (Optional) Item sales tax.
// Note: You must set the currencyID attribute to one of
// the 3-character currency codes for any of the supported PayPal currencies.
// Character length and limitations: Value is a positive number which cannot exceed $10,000 USD in any currency.
// It includes no currency symbol. It must have 2 decimal places, the decimal separator must be a period (.),
// and the optional thousands separator must be a comma (,).
if (parameters["salesTax"] != string.Empty)
{
item.Tax = new BasicAmountType((CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), parameters["currencyCode"]), parameters["salesTax"]);
}
itemTotal += Convert.ToDecimal(qtyItems) * Convert.ToDecimal(amountItems);
orderTotal += itemTotal;
List<PaymentDetailsType> payDetails = new List<PaymentDetailsType>();
//.........这里部分代码省略.........
示例12: ParallelPayment
/// <summary>
/// Handles ParallelPayment
/// </summary>
/// <param name="contextHttp"></param>
private void ParallelPayment(HttpContext contextHttp)
{
NameValueCollection parameters = contextHttp.Request.Params;
// 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);
SetExpressCheckoutRequestType setExpressCheckoutReq = new SetExpressCheckoutRequestType();
SetExpressCheckoutRequestDetailsType details = new SetExpressCheckoutRequestDetailsType();
string requestUrl = ConfigurationManager.AppSettings["HOSTING_ENDPOINT"].ToString();
// (Required) URL to which the buyer's browser is returned after choosing to pay with PayPal. For digital goods, you must add JavaScript to this page to close the in-context experience.
// Note:
// PayPal recommends that the value be the final review page on which the buyer confirms the order and payment or billing agreement.
UriBuilder uriBuilder = new UriBuilder(requestUrl);
uriBuilder.Path = contextHttp.Request.ApplicationPath
+ (contextHttp.Request.ApplicationPath.EndsWith("/") ? string.Empty : "/")
+ "UseCaseSamples/DoExpressCheckoutForParallelPayment.aspx";
string returnUrl = uriBuilder.Uri.ToString();
// (Required) URL to which the buyer is returned if the buyer does not approve the use of PayPal to pay you. For digital goods, you must add JavaScript to this page to close the in-context experience.
// Note:
// PayPal recommends that the value be the original page on which the buyer chose to pay with PayPal or establish a billing agreement.
uriBuilder = new UriBuilder(requestUrl);
uriBuilder.Path = contextHttp.Request.ApplicationPath
+ (contextHttp.Request.ApplicationPath.EndsWith("/") ? string.Empty : "/")
+ "UseCaseSamples/DoExpressCheckout.aspx";
string cancelUrl = uriBuilder.Uri.ToString();
// (Required) URL to which the buyer's browser is returned after choosing
// to pay with PayPal. For digital goods, you must add JavaScript to this
// page to close the in-context experience.
// Note:
// PayPal recommends that the value be the final review page on which the buyer
// confirms the order and payment or billing agreement.
// Character length and limitations: 2048 single-byte characters
details.ReturnURL = returnUrl + "?currencyCodeType=" + parameters["currencyCode"];
details.CancelURL = cancelUrl;
// (Optional) Email address of the buyer as entered during checkout.
// PayPal uses this value to pre-fill the PayPal membership sign-up portion on the PayPal pages.
// Character length and limitations: 127 single-byte alphanumeric characters
details.BuyerEmail = parameters["buyerMail"];
SellerDetailsType seller1 = new SellerDetailsType();
seller1.PayPalAccountID = parameters["receiverEmail_0"];
PaymentDetailsType paymentDetails1 = new PaymentDetailsType();
paymentDetails1.SellerDetails = seller1;
paymentDetails1.PaymentRequestID = parameters["paymentRequestID_0"];
BasicAmountType orderTotal1 = new BasicAmountType();
orderTotal1.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), parameters["currencyCode"]);
orderTotal1.value = parameters["orderTotal"];
paymentDetails1.OrderTotal = orderTotal1;
SellerDetailsType seller2 = new SellerDetailsType();
seller2.PayPalAccountID = parameters["receiverEmail_1"];
PaymentDetailsType paymentDetails2 = new PaymentDetailsType();
paymentDetails2.SellerDetails = seller2;
paymentDetails2.PaymentRequestID = parameters["paymentRequestID_1"];
BasicAmountType orderTotal2 = new BasicAmountType();
orderTotal2.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), parameters["currencyCode"]);
orderTotal2.value = parameters["orderTotal"];
paymentDetails2.OrderTotal = orderTotal2;
List<PaymentDetailsType> payDetails = new List<PaymentDetailsType>();
payDetails.Add(paymentDetails1);
payDetails.Add(paymentDetails2);
details.PaymentDetails = payDetails;
setExpressCheckoutReq.SetExpressCheckoutRequestDetails = details;
SetExpressCheckoutReq expressCheckoutReq = new SetExpressCheckoutReq();
expressCheckoutReq.SetExpressCheckoutRequest = setExpressCheckoutReq;
SetExpressCheckoutResponseType response = null;
try
{
response = service.SetExpressCheckout(expressCheckoutReq);
}
catch (System.Exception ex)
{
contextHttp.Response.Write(ex.Message);
return;
}
Dictionary<string, string> responseValues = new Dictionary<string, string>();
string redirectUrl = null;
if (!response.Ack.ToString().Trim().ToUpper().Equals(AckCode.FAILURE.ToString()) && !response.Ack.ToString().Trim().ToUpper().Equals(AckCode.FAILUREWITHWARNING.ToString()))
{
redirectUrl = ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL"].ToString() + "_express-checkout&token=" + response.Token;
//.........这里部分代码省略.........
示例13: DoExpressCheckoutForParallelPayment
/// <summary>
/// Handles DoExpressCheckoutForParallelPayments
/// </summary>
/// <param name="contextHttp"></param>
private void DoExpressCheckoutForParallelPayment(HttpContext contextHttp)
{
NameValueCollection parameters = contextHttp.Request.Params;
// 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();
// Creating service wrapper object to make an API call by loading configuration map.
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
DoExpressCheckoutPaymentRequestType doCheckoutPaymentRequestType = new DoExpressCheckoutPaymentRequestType();
DoExpressCheckoutPaymentRequestDetailsType details = new DoExpressCheckoutPaymentRequestDetailsType();
// A timestamped token by which you identify to PayPal that you are processing
// this payment with Express Checkout. The token expires after three hours.
// If you set the token in the SetExpressCheckout request, the value of the token
// in the response is identical to the value in the request.
// Character length and limitations: 20 single-byte characters
details.Token = parameters["token"];
// Unique PayPal Customer Account identification number.
// Character length and limitations: 13 single-byte alphanumeric characters
details.PayerID = parameters["payerID"];
// (Optional) How you want to obtain payment. If the transaction does not include a one-time purchase, this field is ignored.
// It is one of the following values:
// Sale – This is a final sale for which you are requesting payment (default).
// Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
// Order – This payment is an order authorization subject to settlement with PayPal Authorization and Capture.
// Note:
// You cannot set this field to Sale in SetExpressCheckout request and then change
// this value to Authorization or Order in the DoExpressCheckoutPayment request.
// If you set the field to Authorization or Order in SetExpressCheckout, you may set the field to Sale.
// Character length and limitations: Up to 13 single-byte alphabetic characters
// This field is deprecated. Use PaymentAction in PaymentDetailsType instead.
details.PaymentAction = (PaymentActionCodeType)Enum.Parse(typeof(PaymentActionCodeType), parameters["paymentType"]);
PaymentDetailsType paymentDetails1 = new PaymentDetailsType();
BasicAmountType orderTotal1 = new BasicAmountType();
orderTotal1.value = parameters["orderTotal"];
//PayPal uses 3-character ISO-4217 codes for specifying currencies in fields and variables.
orderTotal1.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), parameters["currencyCode"]);
// (Required) The total cost of the transaction to the buyer.
// If shipping cost (not applicable to digital goods) 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.
// For digital goods, the following must be true:
// total cost > 0
// total cost <= total cost passed in the call to SetExpressCheckout
// Note:
// You must set the currencyID attribute to one of the 3-character currency codes
// for any of the supported PayPal currencies.
// When multiple payments are passed in one transaction, all of the payments must
// have the same currency code.
// Character length and limitations: Value is a positive number which cannot
// exceed $10,000 USD in any currency. It includes no currency symbol.
// It must have 2 decimal places, the decimal separator must be a period (.),
// and the optional thousands separator must be a comma (,).
paymentDetails1.OrderTotal = orderTotal1;
SellerDetailsType sellerDetailsType1 = new SellerDetailsType();
sellerDetailsType1.PayPalAccountID = parameters["receiverEmail_0"];
paymentDetails1.PaymentRequestID = parameters["paymentRequestID_0"];
paymentDetails1.SellerDetails = sellerDetailsType1;
PaymentDetailsType paymentDetails2 = new PaymentDetailsType();
BasicAmountType orderTotal2 = new BasicAmountType();
orderTotal2.value = parameters["orderTotal"];
//PayPal uses 3-character ISO-4217 codes for specifying currencies in fields and variables.
orderTotal2.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), parameters["currencyCode"]);
// (Required) The total cost of the transaction to the buyer.
// If shipping cost (not applicable to digital goods) 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.
// For digital goods, the following must be true:
// total cost > 0
// total cost <= total cost passed in the call to SetExpressCheckout
// Note:
// You must set the currencyID attribute to one of the 3-character currency codes
// for any of the supported PayPal currencies.
// When multiple payments are passed in one transaction, all of the payments must
//.........这里部分代码省略.........
示例14: CreateRecurringPaymentsProfile
/// <summary>
/// Handles Create Recurring Payments Profile
/// </summary>
/// <param name="contextHttp"></param>
private void CreateRecurringPaymentsProfile(HttpContext contextHttp)
{
NameValueCollection parameters = contextHttp.Request.Params;
// 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);
CreateRecurringPaymentsProfileReq req = new CreateRecurringPaymentsProfileReq();
CreateRecurringPaymentsProfileRequestType reqType = new CreateRecurringPaymentsProfileRequestType();
// (Required) The date when billing for this profile begins.
// Note:
// The profile may take up to 24 hours for activation.
// Character length and limitations: Must be a valid date, in UTC/GMT format
RecurringPaymentsProfileDetailsType profileDetails = new RecurringPaymentsProfileDetailsType(parameters["billingStartDate"] + "T00:00:00:000Z");
// Populate schedule details
ScheduleDetailsType scheduleDetails = new ScheduleDetailsType();
// (Required) Description of the recurring payment.
// Note:
// You must ensure that this field matches the corresponding billing agreement
// description included in the SetExpressCheckout request.
// Character length and limitations: 127 single-byte alphanumeric characters
scheduleDetails.Description = parameters["profileDescription"];
// (Optional) Number of scheduled payments that can fail before the profile
// is automatically suspended. An IPN message is sent to the merchant when the
// specified number of failed payments is reached.
// Character length and limitations: Number string representing an integer
if (parameters["maxFailedPayments"] != string.Empty)
{
scheduleDetails.MaxFailedPayments = Convert.ToInt32(parameters["maxFailedPayments"]);
}
// (Optional) Indicates whether you would like PayPal to automatically bill
// the outstanding balance amount in the next billing cycle.
// The outstanding balance is the total amount of any previously failed
// scheduled payments that have yet to be successfully paid.
// It is one of the following values:
// NoAutoBill – PayPal does not automatically bill the outstanding balance.
// AddToNextBilling – PayPal automatically bills the outstanding balance.
if (parameters["autoBillOutstandingAmount"] != string.Empty)
{
scheduleDetails.AutoBillOutstandingAmount = (AutoBillType)Enum.Parse(typeof(AutoBillType), parameters["autoBillOutstandingAmount"]);
}
CurrencyCodeType currency = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), "USD");
if (parameters["trialBillingAmount"] != string.Empty)
{
// Number of billing periods that make up one billing cycle;
// required if you specify an optional trial period.
// The combination of billing frequency and billing period must be
// less than or equal to one year. For example, if the billing cycle is Month,
// the maximum value for billing frequency is 12. Similarly,
// if the billing cycle is Week, the maximum value for billing frequency is 52.
// Note:
// If the billing period is SemiMonth, the billing frequency must be 1.
int frequency = Convert.ToInt32(parameters["trialBillingFrequency"]);
// Billing amount for each billing cycle during this payment period;
// required if you specify an optional trial period.
// This amount does not include shipping and tax amounts.
// Note:
// All amounts in the CreateRecurringPaymentsProfile request must have
// the same currency.
// Character length and limitations:
// Value is a positive number which cannot exceed $10,000 USD in any currency.
// It includes no currency symbol.
// It must have 2 decimal places, the decimal separator must be a period (.),
// and the optional thousands separator must be a comma (,).
BasicAmountType paymentAmount = new BasicAmountType(currency, parameters["trialBillingAmount"]);
// Unit for billing during this subscription period;
// required if you specify an optional trial period.
// It is one of the following values: [Day, Week, SemiMonth, Month, Year]
// For SemiMonth, billing is done on the 1st and 15th of each month.
// Note:
// The combination of BillingPeriod and BillingFrequency cannot exceed one year.
BillingPeriodType period = (BillingPeriodType)Enum.Parse(typeof(BillingPeriodType), parameters["trialBillingPeriod"]);
// Number of billing periods that make up one billing cycle;
// required if you specify an optional trial period.
// The combination of billing frequency and billing period must be
// less than or equal to one year. For example, if the billing cycle is Month,
// the maximum value for billing frequency is 12. Similarly,
// if the billing cycle is Week, the maximum value for billing frequency is 52.
// Note:
// If the billing period is SemiMonth, the billing frequency must be 1.
int numCycles = Convert.ToInt32(parameters["trialBillingCycles"]);
//.........这里部分代码省略.........
示例15: DoCapture
/// <summary>
/// Handles DoCapture
/// </summary>
/// <param name="contextHttp"></param>
private void DoCapture(HttpContext contextHttp)
{
NameValueCollection parameters = contextHttp.Request.Params;
// 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();
// Creating service wrapper object to make an API call by loading configuration map.
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
// ## DoCaptureReq
DoCaptureReq req = new DoCaptureReq();
// 'Amount' to capture which takes mandatory params:
//
// * 'currencyCode'
// * 'amount'
BasicAmountType amount = new BasicAmountType(((CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), parameters["currencyCode"])), parameters["amt"]);
// 'DoCaptureRequest' which takes mandatory params:
//
// * 'Authorization ID' - Authorization identification number of the
// payment you want to capture. This is the transaction ID returned from
// DoExpressCheckoutPayment, DoDirectPayment, or CheckOut. For
// point-of-sale transactions, this is the transaction ID returned by
// the CheckOut call when the payment action is Authorization.
// * 'amount' - Amount to capture
// * 'CompleteCode' - Indicates whether or not this is your last capture.
// It is one of the following values:
// * Complete – This is the last capture you intend to make.
// * NotComplete – You intend to make additional captures.
// 'Note:
// If Complete, any remaining amount of the original authorized
// transaction is automatically voided and all remaining open
// authorizations are voided.'
DoCaptureRequestType reqType = new DoCaptureRequestType
(
parameters["authID"],
amount,
(CompleteCodeType)Enum.Parse(typeof(CompleteCodeType), parameters["completeCodeType"])
);
req.DoCaptureRequest = reqType;
DoCaptureResponseType response = null;
try
{
response = service.DoCapture(req);
}
catch (System.Exception ex)
{
contextHttp.Response.Write(ex.StackTrace);
return;
}
Dictionary<string, string> responseValues = new Dictionary<string, string>();
string redirectUrl = null;
responseValues.Add("Acknowledgement", response.Ack.ToString().Trim().ToUpper());
Display(contextHttp, "DoCapture", "DoCapture", responseValues, service.getLastRequest(), service.getLastResponse(), response.Errors, redirectUrl);
}