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"); }
protected void Page_Load(object sender, EventArgs e) { HttpContext CurrContext = HttpContext.Current; Refund refund = null; 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(); // ###Authorization // Retrieve a Authorization object // by making a Payment with intent // as 'authorize' Authorization authorization = GetAuthorization(accessToken); /// ###Capture // Create a Capture object // by doing a capture on // Authorization object Capture capture = GetCapture(accessToken, authorization); /// ###Refund /// Create a Refund object refund = new Refund(); // ###Amount // Let's you specify a capture amount. Amount refundAmount = new Amount(); refundAmount.currency = "USD"; refundAmount.total = "1"; refund.amount = refundAmount; // Do a Refund by // POSTing to // URI v1/payments/capture/{capture_id}/refund Refund responseRefund = capture.Refund(accessToken, refund); CurrContext.Items.Add("ResponseJson", JObject.Parse(responseRefund.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"); }
protected void Page_Load(object sender, EventArgs e) { HttpContext CurrContext = HttpContext.Current; Refund refund = null; try { // ### 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. // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.. APIContext apiContext = Configuration.GetAPIContext(); // ###Authorization // Retrieve a Authorization object // by making a Payment with intent // as 'authorize' Authorization authorization = Common.CreateAuthorization(apiContext); /// ###Capture // Create a Capture object // by doing a capture on // Authorization object Capture capture = Common.GetCapture(apiContext, authorization); /// ###Refund /// Create a Refund object refund = new Refund(); // ###Amount // Let's you specify a capture amount. Amount refundAmount = new Amount(); refundAmount.currency = "USD"; refundAmount.total = "0.50"; refund.amount = refundAmount; // Do a Refund by // POSTing to // URI v1/payments/capture/{capture_id}/refund Refund responseRefund = capture.Refund(Configuration.GetAPIContext(), refund); CurrContext.Items.Add("ResponseJson", JObject.Parse(responseRefund.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"); }
public Refund CreateRefund() { List<Links> links = new List<Links>(); links.Add(CreateLinks()); Refund refund = new Refund(); refund.capture_id = "101"; refund.id = "102"; refund.parent_payment = "103"; refund.sale_id = "104"; refund.state = "Approved"; refund.amount = GetAmount(); refund.create_time = "2013-01-17T18:12:02.347Z"; refund.links = links; return refund; }
/// <summary> /// Creates (and processes) a new Refund Transaction added as a related resource. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <param name="refund">Refund</param> /// <returns>Refund</returns> public Refund Refund(APIContext apiContext, Refund refund) { // Validate the arguments to be used in the request ArgumentValidator.ValidateAndSetupAPIContext(apiContext); ArgumentValidator.Validate(this.id, "Id"); ArgumentValidator.Validate(refund, "refund"); // Configure and send the request object[] parameters = new object[] { this.id }; string pattern = "v1/payments/order/{0}/refund"; string resourcePath = SDKUtil.FormatURIPath(pattern, parameters); string payLoad = refund.ConvertToJson(); return(PayPalResource.ConfigureAndExecute <Refund>(apiContext, HttpMethod.POST, resourcePath, payLoad)); }
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 = "7X350557WR366683S"; try { // ### 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. // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.. APIContext apiContext = Configuration.GetAPIContext(); // Refund by posting Refund object using a valid APIContext 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"); }
/// <summary> /// Creates (and processes) a new Refund Transaction added as a related resource. /// </summary> public Refund Refund(APIContext apiContext, Refund refund) { if (string.IsNullOrEmpty(apiContext.AccessToken)) { throw new ArgumentNullException("AccessToken cannot be null or empty"); } if (this.id == null) { throw new ArgumentNullException("Id cannot be null"); } if (refund == null) { throw new ArgumentNullException("refund cannot be null"); } object[] parameters = new object[] { this.id }; string pattern = "v1/payments/capture/{0}/refund"; string resourcePath = SDKUtil.FormatURIPath(pattern, parameters); string payLoad = refund.ConvertToJson(); return(PayPalResource.ConfigureAndExecute <Refund>(apiContext, HttpMethod.POST, resourcePath, payLoad)); }
public void RefundCaptureTest() { Payment payment = GetPaymentObject(AccessToken); string authorizationId = payment.transactions[0].related_resources[0].authorization.id; Authorization authorization = Authorization.Get(AccessToken, authorizationId); Capture capture = new Capture(); Amount amount = new Amount(); amount.total = "1"; amount.currency = "USD"; capture.amount = amount; Capture response = authorization.Capture(AccessToken, capture); Refund refund = new Refund(); Amount rAmount = new Amount(); rAmount.total = "1"; rAmount.currency = "USD"; refund.amount = rAmount; Refund responseRefund = response.Refund(AccessToken, refund); Assert.AreEqual("completed", responseRefund.state); }
/// <summary> /// Creates (and processes) a new Refund Transaction added as a related resource. /// </summary> /// <param name="accessToken">Access Token used for the API call.</param> /// <param name="refund">Refund</param> /// <returns>Refund</returns> public Refund Refund(string accessToken, Refund refund) { APIContext apiContext = new APIContext(accessToken); return(Refund(apiContext, refund)); }
/// <summary> /// Refund call for Sale. /// POST /v1/payments/sale/:saleId/refund /// <param name="apiContext">APIContext used for the API call</param> /// <param name="refund">Refund</param> /// <returns>Returns Refund object</returns> /// </summary> public Refund Refund(APIContext apiContext, Refund refund) { if (string.IsNullOrEmpty(apiContext.AccessToken)) { throw new ArgumentNullException("AccessToken cannot be null"); } if (refund == null) { throw new System.ArgumentNullException("refund cannot be null"); } if (this.id == null) { throw new System.ArgumentNullException("Id cannot be null"); } string pattern = "v1/payments/sale/{0}/refund"; object[] container = new Object[] { this.id }; string resourcePath = SDKUtil.FormatURIPath(pattern, container); string payLoad = refund.ConvertToJson(); return PayPalResource.ConfigureAndExecute<Refund>(apiContext, HttpMethod.POST, resourcePath, payLoad); }
/// <summary> /// Refund call for Sale. /// POST /v1/payments/sale/:saleId/refund /// <param name="accessToken">Access Token</param> /// <param name="refund">Refund</param> /// <returns>Returns Refund object</returns> /// </summary> public Refund Refund(string accessToken, Refund refund) { APIContext apiContext = new APIContext(accessToken); return Refund(apiContext, refund); }
/// <summary> /// Creates (and processes) a new Refund Transaction added as a related resource. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <param name="refund">Refund</param> /// <returns>Refund</returns> public Refund Refund(APIContext apiContext, Refund refund) { 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(); if (this.id == null) { throw new ArgumentNullException("Id cannot be null"); } if (refund == null) { throw new ArgumentNullException("refund cannot be null"); } object[] parameters = new object[] {this.id}; string pattern = "v1/payments/sale/{0}/refund"; string resourcePath = SDKUtil.FormatURIPath(pattern, parameters); string payLoad = refund.ConvertToJson(); return PayPalResource.ConfigureAndExecute<Refund>(apiContext, HttpMethod.POST, resourcePath, payLoad); }
public void RefundIdTest() { Payment pay = GetPayment(); string authorizationId = pay.transactions[0].related_resources[0].authorization.id; Authorization authorization = Authorization.Get(AccessToken, authorizationId); Capture cap = new Capture(); Amount amt = new Amount(); amt.total = "1"; amt.currency = "USD"; cap.amount = amt; Capture response = authorization.Capture(AccessToken, cap); Refund fund = new Refund(); Amount refundAmount = new Amount(); refundAmount.total = "1"; refundAmount.currency = "USD"; fund.amount = refundAmount; Refund responseRefund = response.Refund(AccessToken, fund); Refund retrievedRefund = Refund.Get(AccessToken, responseRefund.id); Assert.AreEqual(responseRefund.id, retrievedRefund.id); }
public void RefundCaptureTest() { Payment pay = GetPayment(); string authorizationId = pay.transactions[0].related_resources[0].authorization.id; Authorization authorization = Authorization.Get(UnitTestUtil.GetApiContext(), authorizationId); Capture cap = new Capture(); Amount amnt = new Amount(); amnt.total = "1"; amnt.currency = "USD"; cap.amount = amnt; Capture response = authorization.Capture(UnitTestUtil.GetApiContext(), cap); Refund fund = new Refund(); Amount refundAmount = new Amount(); refundAmount.total = "1"; refundAmount.currency = "USD"; fund.amount = refundAmount; Refund responseRefund = response.Refund(UnitTestUtil.GetApiContext(), fund); Assert.AreEqual("completed", responseRefund.state); }