本文整理汇总了C#中PayPal.APIContext类的典型用法代码示例。如果您正苦于以下问题:C# APIContext类的具体用法?C# APIContext怎么用?C# APIContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
APIContext类属于PayPal命名空间,在下文中一共展示了APIContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
HttpContext CurrContext = HttpContext.Current;
// ###Amount
// Create an Amount object to
// represent the amount to be
// refunded. Create the refund object, if the refund is partial
Amount amount = new Amount();
amount.currency = "USD";
amount.total = "0.01";
// ###Refund
// A refund transaction.
// Use the amount to create
// a refund object
Refund refund = new Refund();
refund.amount = amount;
// ###Sale
// A sale transaction.
// Create a Sale object with the
// given sale transaction id.
Sale sale = new Sale();
sale.id = "03W403310B593121A";
try
{
// ###AccessToken
// Retrieve the access token from
// OAuthTokenCredential by passing in
// ClientID and ClientSecret
// It is not mandatory to generate Access Token on a per call basis.
// Typically the access token can be generated once and
// reused within the expiry window
string accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken();
// ### Api Context
// Pass in a `ApiContext` object to authenticate
// the call and to send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
APIContext apiContext = new APIContext(accessToken);
// Use this variant if you want to pass in a request id
// that is meaningful in your application, ideally
// a order id.
// String requestId = Long.toString(System.nanoTime();
// APIContext apiContext = new APIContext(accessToken, requestId ));
// Refund by posting to the APIService
// using a valid AccessToken
Refund refundedSale = sale.Refund(apiContext, refund);
CurrContext.Items.Add("ResponseJson",JObject.Parse(refundedSale.ConvertToJson()).ToString(Formatting.Indented));
}
catch (PayPal.Exception.PayPalException ex)
{
CurrContext.Items.Add("Error", ex.Message);
}
CurrContext.Items.Add("RequestJson",
JObject.Parse(refund.ConvertToJson()).ToString(Formatting.Indented));
Server.Transfer("~/Response.aspx");
}
示例2: Create
public static APIContext Create()
{
var config = ConfigManager.Instance.GetProperties();
var credentials = new OAuthTokenCredential(
config[BaseConstants.ClientId],
config[BaseConstants.ClientSecret]
);
// ### Api Context
// Pass in a `APIContext` object to authenticate
// the call and to send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
var apiContext = new APIContext(credentials.GetAccessToken())
{
Config = config
};
// Use this variant if you want to pass in a request id
// that is meaningful in your application, ideally
// a order id.
// String requestId = Long.toString(System.nanoTime();
// APIContext apiContext = new APIContext(GetAccessToken(), requestId ));
return apiContext;
}
示例3: DomEndpointTest
public void DomEndpointTest()
{
APIContext baseAPIContext = new APIContext();
Dictionary<string, string> configurationMap = new Dictionary<string, string>();
configurationMap.Add("endpoint", "https://api-3t.sandbox.paypal.com/2.0");
DefaultSOAPAPICallHandler defHandler = new DefaultSOAPAPICallHandler(new SampleBody(), baseAPIContext, configurationMap, "DoDirectPayment");
Assert.AreEqual("https://api-3t.sandbox.paypal.com/2.0", defHandler.GetEndpoint());
}
示例4: APIContextConstructorTest
public void APIContextConstructorTest()
{
string tokenAccess = AccessToken;
string requestId = Convert.ToString(Guid.NewGuid());
APIContext apiContext = new APIContext(tokenAccess, requestId);
Assert.IsNotNull(apiContext);
Assert.AreEqual(tokenAccess, apiContext.AccessToken);
Assert.AreEqual(requestId, apiContext.RequestID);
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
HttpContext CurrContext = HttpContext.Current;
// ###CreditCard
// A resource representing a credit card that can be
// used to fund a payment.
CreditCard credtCard = new CreditCard();
credtCard.expire_month = "11";
credtCard.expire_year = "2018";
credtCard.number = "4417119669820331";
credtCard.type = "visa";
try
{
// ###AccessToken
// Retrieve the access token from
// OAuthTokenCredential by passing in
// ClientID and ClientSecret
// It is not mandatory to generate Access Token on a per call basis.
// Typically the access token can be generated once and
// reused within the expiry window
string accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperty("ClientID"), ConfigManager.Instance.GetProperty("ClientSecret")).GetAccessToken();
// ### Api Context
// Pass in a `ApiContext` object to authenticate
// the call and to send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
APIContext apiContext = new APIContext(accessToken);
// Use this variant if you want to pass in a request id
// that is meaningful in your application, ideally
// a order id.
// String requestId = Long.toString(System.nanoTime();
// APIContext apiContext = new APIContext(accessToken, requestId ));
// ###Save
// Creates the credit card as a resource
// in the PayPal vault. The response contains
// an 'id' that you can use to refer to it
// in the future payments.
CreditCard createdCreditCard = credtCard.Create(apiContext);
CurrContext.Items.Add("ResponseJson", JObject.Parse(createdCreditCard.ConvertToJson()).ToString(Formatting.Indented));
}
catch (PayPal.Exception.PayPalException ex)
{
CurrContext.Items.Add("Error", ex.Message);
}
CurrContext.Items.Add("RequestJson", JObject.Parse(credtCard.ConvertToJson()).ToString(Formatting.Indented));
Server.Transfer("~/Response.aspx");
}
示例6: GetAPIContext
// Returns APIContext object
public static APIContext GetAPIContext()
{
// ### Api Context
// Pass in a `APIContext` object to authenticate
// the call and to send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
APIContext apiContext = new APIContext(GetAccessToken());
apiContext.Config = GetConfig();
// Use this variant if you want to pass in a request id
// that is meaningful in your application, ideally
// a order id.
// String requestId = Long.toString(System.nanoTime();
// APIContext apiContext = new APIContext(GetAccessToken(), requestId ));
return apiContext;
}
示例7: Capture
public ActionResult Capture(string authorizationId)
{
var viewData = new PayPalViewData();
try
{
var accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken();
var apiContext = new APIContext(accessToken);
var authorization = Authorization.Get(apiContext, authorizationId);
if (authorization != null)
{
var total = Convert.ToDecimal(authorization.amount.total);
var capture = authorization.Capture(apiContext, new Capture
{
is_final_capture = true,
amount = new Amount
{
currency = "USD",
total = (total + (total * .05m)).ToString("f2")
},
});
viewData.JsonResponse = JObject.Parse(capture.ConvertToJson()).ToString(Formatting.Indented);
return View("Success", viewData);
}
viewData.ErrorMessage = "Could not find previous authorization.";
return View("Error", viewData);
}
catch (PayPalException ex)
{
viewData.ErrorMessage = ex.Message;
return View("Error", viewData);
}
}
示例8: DomPayloadTest
public void DomPayloadTest()
{
DefaultSOAPAPICallHandler.XMLNamespaceProvider = new XmlNamespacePrefixProvider();
APIContext api = new APIContext();
api.SOAPHeader = new SampleHeader();
Dictionary<string, string> configurationMap = new Dictionary<string, string>();
configurationMap.Add("service.EndPoint", "https://api-3t.sandbox.paypal.com/2.0");
api.Config = configurationMap;
DefaultSOAPAPICallHandler defHandler = new DefaultSOAPAPICallHandler(new SampleBody(), api, null, "DoDirectPayment");
string payload = defHandler.GetPayload().Trim();
string expectedPayload = "<soapenv:Envelope xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" xmlns:ed=\"urn:ebay:apis:EnhancedDataTypes\" xmlns:cc=\"urn:ebay:apis:CoreComponentTypes\" xmlns:ebl=\"urn:ebay:apis:eBLBaseComponents\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsdlsoap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:ns=\"urn:ebay:api:PayPalAPI\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soapenv:Header>" +
"<ns:RequesterCredentials>" +
"<ebl:Credentials>" +
"<ebl:Username>jb-us-seller_api1.paypal.com</ebl:Username>" +
"</ebl:Credentials>" +
"</ns:RequesterCredentials>" +
"</soapenv:Header>" +
"<soapenv:Body>" +
"<ns:DoDirectPaymentReq>" +
"<ns:DoDirectPaymentRequest>" +
"<ebl:Version>98.0</ebl:Version>" +
"<ebl:DoDirectPaymentRequestDetails>" +
"<ebl:CreditCard>" +
"<ebl:CreditCardType>Visa</ebl:CreditCardType>" +
"<ebl:CreditCardNumber>4202297003827029</ebl:CreditCardNumber>" +
"<ebl:CVV2>962</ebl:CVV2>" +
"</ebl:CreditCard>" +
"</ebl:DoDirectPaymentRequestDetails>" +
"</ns:DoDirectPaymentRequest>" +
"</ns:DoDirectPaymentReq>" +
"</soapenv:Body>" +
"</soapenv:Envelope>";
Assert.AreEqual(expectedPayload, payload);
}
示例9: Confirmed
public ActionResult Confirmed(Guid id, string token, string payerId)
{
var viewData = new OrderConfirmedViewData
{
Id = id,
Token = token,
PayerId = payerId
};
var accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken();
var apiContext = new APIContext(accessToken);
var payment = new Payment()
{
id = (string)Session[id.ToString()],
};
var executedPayment = payment.Execute(apiContext, new PaymentExecution { payer_id = payerId });
viewData.AuthorizationId = executedPayment.transactions[0].related_resources[0].authorization.id;
viewData.JsonRequest = JObject.Parse(payment.ConvertToJson()).ToString(Formatting.Indented);
viewData.JsonResponse = JObject.Parse(executedPayment.ConvertToJson()).ToString(Formatting.Indented);
return View(viewData);
}
示例10: Get
/// <summary>
/// Obtain the Payment resource for the given identifier.
/// </summary>
public static Payment Get(APIContext apiContext, string paymentId)
{
if (string.IsNullOrEmpty(apiContext.AccessToken))
{
throw new ArgumentNullException("AccessToken cannot be null or empty");
}
if (paymentId == null)
{
throw new ArgumentNullException("paymentId cannot be null");
}
object[] parameters = new object[] {paymentId};
string pattern = "v1/payments/payment/{0}";
string resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
string payLoad = "";
return PayPalResource.ConfigureAndExecute<Payment>(apiContext, HttpMethod.GET, resourcePath, payLoad);
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
HttpContext CurrContext = HttpContext.Current;
Payment pymnt = null;
// ## ExecutePayment
if (Request.Params["PayerID"] != null)
{
pymnt = new Payment();
if (Request.Params["guid"] != null)
{
pymnt.id = (string)Session[Request.Params["guid"]];
}
try
{
// ###AccessToken
// Retrieve the access token from
// OAuthTokenCredential by passing in
// ClientID and ClientSecret
// It is not mandatory to generate Access Token on a per call basis.
// Typically the access token can be generated once and
// reused within the expiry window
string accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken();
// ### Api Context
// Pass in a `ApiContext` object to authenticate
// the call and to send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
APIContext apiContext = new APIContext(accessToken);
// Use this variant if you want to pass in a request id
// that is meaningful in your application, ideally
// a order id.
// String requestId = Long.toString(System.nanoTime();
// APIContext apiContext = new APIContext(accessToken, requestId ));
PaymentExecution pymntExecution = new PaymentExecution();
pymntExecution.payer_id = Request.Params["PayerID"];
Payment executedPayment = pymnt.Execute(apiContext,
pymntExecution);
CurrContext.Items.Add("ResponseJson", JObject.Parse(executedPayment.ConvertToJson()).ToString(Formatting.Indented));
}
catch (PayPal.Exception.PayPalException ex)
{
CurrContext.Items.Add("Error", ex.Message);
}
}
// ## Creating Payment
else
{
// ###Payer
// A resource representing a Payer that funds a payment
// Payment Method
// as `paypal`
Payer payr = new Payer();
payr.payment_method = "paypal";
Random rndm = new Random();
var guid = Convert.ToString(rndm.Next(100000));
string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/PaymentWithPayPal.aspx?";
// # Redirect URLS
RedirectUrls redirUrls = new RedirectUrls();
redirUrls.cancel_url = baseURI + "guid=" + guid;
redirUrls.return_url = baseURI + "guid=" + guid;
// ###Details
// Let's you specify details of a payment amount.
Details details = new Details();
details.tax = "15";
details.shipping = "10";
details.subtotal = "75";
// ###Amount
// Let's you specify a payment amount.
Amount amnt = new Amount();
amnt.currency = "USD";
// Total must be equal to sum of shipping, tax and subtotal.
amnt.total = "100";
amnt.details = details;
// ###Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it. Transaction is created with
// a `Payee` and `Amount` types
List<Transaction> transactionList = new List<Transaction>();
Transaction tran = new Transaction();
tran.description = "Transaction description.";
tran.amount = amnt;
// The Payment creation API requires a list of
// Transaction; add the created `Transaction`
// to a List
transactionList.Add(tran);
// ###Payment
// A Payment Resource; create one using
// the above types and intent as 'sale'
//.........这里部分代码省略.........
示例12: Create
/// <summary>
/// Creates (and processes) a new Payment Resource.
/// </summary>
/// <param name="apiContext">APIContext used for the API call.</param>
/// <returns>Payment</returns>
public Payment Create(APIContext apiContext)
{
if (apiContext == null)
{
throw new ArgumentNullException("APIContext cannot be null");
}
if (string.IsNullOrEmpty(apiContext.AccessToken))
{
throw new ArgumentNullException("AccessToken cannot be null or empty");
}
if (apiContext.HTTPHeaders == null)
{
apiContext.HTTPHeaders = new Dictionary<string, string>();
}
apiContext.HTTPHeaders.Add(BaseConstants.ContentTypeHeader, BaseConstants.ContentTypeHeaderJson);
apiContext.SdkVersion = new SDKVersionImpl();
string resourcePath = "v1/payments/payment";
string payLoad = this.ConvertToJson();
return PayPalResource.ConfigureAndExecute<Payment>(apiContext, HttpMethod.POST, resourcePath, payLoad);
}
示例13: PaymentHistoryTest
public void PaymentHistoryTest()
{
APIContext context = new APIContext(AccessToken);
Dictionary<string, string> containerDictionary = new Dictionary<string, string>();
containerDictionary.Add("count", "10");
PaymentHistory paymentHistory = Payment.List(context, containerDictionary);
Assert.AreEqual(10, paymentHistory.count);
}
示例14: Create
/// <summary>
/// Creates (and processes) a new Payment Resource.
/// </summary>
public Payment Create(string accessToken)
{
APIContext apiContext = new APIContext(accessToken);
return Create(apiContext);
}
示例15: Execute
/// <summary>
/// Executes the payment (after approved by the Payer) associated with this resource when the payment method is PayPal.
/// </summary>
public Payment Execute(string accessToken, PaymentExecution paymentExecution)
{
APIContext apiContext = new APIContext(accessToken);
return Execute(apiContext, paymentExecution);
}