Ejemplo n.º 1
0
        public void TestRefundCreated()
        {
            // Arrange
            Refund refund = new Refund()
            {
                RefundedAmount = 12345,
                Description    = "Refund description"
            };

            this.requestMock.Expect(x => x.CreateRequest(this.baseUrl.ToString().TrimEnd('/') + this.path + '/' + this.orderId + "/refunds")).Return(this.httpWebRequest);

            WebHeaderCollection headers = new WebHeaderCollection();

            headers["Location"] = this.location;

            IResponse response = new Response(HttpStatusCode.Created, headers, string.Empty);

            this.requestMock.Expect(x => x.Send(this.httpWebRequest, refund.ConvertToJson())).Return(response);

            // Act
            this.order.Refund(refund);

            // Assert
            this.requestMock.VerifyAllExpectations();
            Assert.AreEqual(this.httpWebRequest.ContentLength, refund.ConvertToJson().Length);
            TestsHelper.AssertRequest(this.merchantId, this.secret, this.httpWebRequest, HttpMethod.Post);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext CurrContext = HttpContext.Current;

            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
                // Pass an APIContext and the ID of the refunded
                // transaction
                Refund refund = Refund.Get(apiContext, "7B165985YD577493B");
                CurrContext.Items.Add("ResponseJson", JObject.Parse(refund.ConvertToJson()).ToString(Formatting.Indented));
            }
            catch (PayPal.Exception.PayPalException ex)
            {
                CurrContext.Items.Add("Error", ex.Message);
            }
            Server.Transfer("~/Response.aspx");
        }
Ejemplo n.º 3
0
        public void Order_Refund_Basic_Created()
        {
            // Arrange
            Refund refund = TestsHelper.GetRefund();

            TestsHelper.Mock(HttpMethod.Post, this.order.Location + "/refunds", refund.ConvertToJson(), HttpStatusCode.Created, this.connectorMock);

            this.order.Refund(refund);
        }
        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");
        }
Ejemplo n.º 6
0
        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");
        }
        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 = "4V7971043K262623A";
            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(sale.ConvertToJson()).ToString(Formatting.Indented));
            Server.Transfer("~/Response.aspx");
        }