private Capture GetCapture()
 {
     Capture cap = new Capture();
     cap.amount = GetAmount();
     cap.create_time = "2013-01-15T15:10:05.123Z";
     cap.state = "Authorized";
     cap.parent_payment = "1000";
     cap.links = GetLinksList();
     cap.id = "001";
     return cap;
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext CurrContext = HttpContext.Current;
            Capture capture = 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);

                // ###Amount
                // Let's you specify a capture amount.
                Amount amnt = new Amount();
                amnt.currency = "USD";
                amnt.total = "4.54";

                capture = new Capture();
                capture.amount = amnt;

                // ##IsFinalCapture
                // If set to true, all remaining 
                // funds held by the authorization 
                // will be released in the funding 
                // instrument. Default is `false`.
                capture.is_final_capture = true;                      
                
                // Capture an authorized payment by POSTing to
                // URI v1/payments/authorization/{authorization_id}/capture
                Capture responseCapture = authorization.Capture(apiContext, capture);
                CurrContext.Items.Add("ResponseJson", JObject.Parse(responseCapture.ConvertToJson()).ToString(Formatting.Indented));
            }
            catch (PayPal.Exception.PayPalException ex)
            {
                CurrContext.Items.Add("Error", ex.Message);
            }

            if (capture != null)
            {
                CurrContext.Items.Add("RequestJson", JObject.Parse(capture.ConvertToJson()).ToString(Formatting.Indented));
            }

            Server.Transfer("~/Response.aspx");

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext CurrContext = HttpContext.Current;
            Capture capture = 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);

                // ###Amount
                // Let's you specify a capture amount.
                Amount amnt = new Amount();
                amnt.currency = "USD";
                amnt.total = "4.54";

                capture = new Capture();
                capture.amount = amnt;

                // ##IsFinalCapture
                // If set to true, all remaining
                // funds held by the authorization
                // will be released in the funding
                // instrument. Default is ‘false’.
                capture.is_final_capture = true;

                // Capture by POSTing to
                // URI v1/payments/authorization/{authorization_id}/capture
                Capture responseCapture = authorization.Capture(accessToken, capture);
                CurrContext.Items.Add("ResponseJson", JObject.Parse(responseCapture.ConvertToJson()).ToString(Formatting.Indented));

            }
            catch (PayPal.Exception.PayPalException ex)
            {
                CurrContext.Items.Add("Error", ex.Message);
            }
            CurrContext.Items.Add("RequestJson", JObject.Parse(capture.ConvertToJson()).ToString(Formatting.Indented));

            Server.Transfer("~/Response.aspx");
        }
 public void CaptureConstructorTest()
 {
     Capture target = new Capture();
     Assert.IsNotNull(target);
 }
 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);
 }
 public void GetCaptureTest()
 {
     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);
     Capture returnCapture = Capture.Get(AccessToken, response.id);
     Assert.AreEqual(response.id, returnCapture.id);
 }
 public void AuthorizationCaptureTest()
 {
     Payment pay = CreatePayment();
     string authorizationId = pay.transactions[0].related_resources[0].authorization.id;
     Authorization authorize = Authorization.Get(UnitTestUtil.GetApiContext(), authorizationId);
     Capture cap = new Capture();
     Amount amt = new Amount();
     amt.total = "1";
     amt.currency = "USD";
     cap.amount = amt;
     Capture response = authorize.Capture(UnitTestUtil.GetApiContext(), cap);
     Assert.AreEqual("completed", response.state);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates (and processes) a new Capture Transaction added as a related resource.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="capture">Capture</param>
 /// <returns>Capture</returns>
 public Capture Capture(APIContext apiContext, Capture capture)
 {
     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 (capture == null)
     {
         throw new ArgumentNullException("capture cannot be null");
     }
     object[] parameters = new object[] {this.id};
     string pattern = "v1/payments/authorization/{0}/capture";
     string resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
     string payLoad = capture.ConvertToJson();
     return PayPalResource.ConfigureAndExecute<Capture>(apiContext, HttpMethod.POST, resourcePath, payLoad);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Creates (and processes) a new Capture Transaction added as a related resource.
 /// </summary>
 /// <param name="accessToken">Access Token used for the API call.</param>
 /// <param name="capture">Capture</param>
 /// <returns>Capture</returns>
 public Capture Capture(string accessToken, Capture capture)
 {
     APIContext apiContext = new APIContext(accessToken);
     return Capture(apiContext, capture);
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
		/// <summary>
		/// Creates (and processes) a new Capture Transaction added as a related resource.
		/// </summary>
		/// <param name="apiContext">APIContext used for the API call.</param>
		/// <param name="capture">Capture</param>
		/// <returns>Capture</returns>
		public Capture Capture(APIContext apiContext, Capture capture)
		{
			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 (capture == null)
			{
				throw new ArgumentNullException("capture cannot be null");
			}
			object[] parameters = new object[] {this.id};
			string pattern = "v1/payments/authorization/{0}/capture";
			string resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
			string payLoad = capture.ConvertToJson();
			return PayPalResource.ConfigureAndExecute<Capture>(apiContext, HttpMethod.POST, resourcePath, payLoad);
		}
Exemplo n.º 12
0
        public static Capture GetCapture(APIContext apiContext, Authorization authorization)
        {
            // ###Amount
            // Let's you specify a capture amount.
            Amount amnt = new Amount();
            amnt.currency = "USD";
            amnt.total = "1.00";

            Capture capture = new Capture();
            capture.amount = amnt;

            // ##IsFinalCapture
            // If set to true, all remaining 
            // funds held by the authorization 
            // will be released in the funding 
            // instrument. Default is ‘false’.
            capture.is_final_capture = true;

            // Capture by POSTing to
            // URI v1/payments/authorization/{authorization_id}/capture
            Capture responseCapture = authorization.Capture(apiContext, capture);

            return responseCapture;
        }
Exemplo n.º 13
0
 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);
 }
Exemplo n.º 14
0
 public void CaptureIdTest()
 {
     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 amt = new Amount();
     amt.total = "1";
     amt.currency = "USD";
     cap.amount = amt;
     Capture responseCapture = authorization.Capture(UnitTestUtil.GetApiContext(), cap);
     Capture returnCapture = Capture.Get(UnitTestUtil.GetApiContext(), responseCapture.id);
     Assert.AreEqual(responseCapture.id, returnCapture.id);
 }
        private string GetCaptureId(string accessToken, Authorization authorization)
        {
            // ###Amount
            // Let's you specify a capture amount.
            Amount amnt = new Amount();
            amnt.currency = "USD";
            amnt.total = "4.54";

            Capture capture = new Capture();
            capture.amount = amnt;

            // ##IsFinalCapture
            // If set to true, all remaining
            // funds held by the authorization
            // will be released in the funding
            // instrument. Default is ‘false’.
            capture.is_final_capture = true;

            // Capture by POSTing to
            // URI v1/payments/authorization/{authorization_id}/capture
            Capture responseCapture = authorization.Capture(accessToken, capture);

            return responseCapture.id;
        }