public static async Task <Plan> CreateBillingPlan(string name, string description, string baseUrl) { var client = PayPalConfiguration.GetClient(); var returnUrl = baseUrl + "/Home/SubscribeSuccess"; var cancelUrl = baseUrl + "/Home/SubscribeCancel"; // Plan Details var plan = CreatePlanObject("Test Plan", "Plan for Tuts+", returnUrl, cancelUrl, PlanInterval.Month, 1, (decimal)19.90, trial: true, trialLength: 1, trialPrice: 0); PlanCreateRequest request = new PlanCreateRequest(); request.RequestBody(plan); try { HttpResponse response = await client.Execute(request); var statusCode = response.StatusCode; return(response.Result <Plan>()); } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw httpException; } }
public static async Task <Agreement> CancelBillingAgreement(string agreementId) { var client = PayPalConfiguration.GetClient(); AgreementCancelRequest request = new AgreementCancelRequest(agreementId); request.RequestBody(new AgreementStateDescriptor { Note = "Cancelling the agreement" }); try { HttpResponse response = await client.Execute(request); var statusCode = response.StatusCode; return(response.Result <Agreement>()); } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw httpException; } }
public static async Task <Payment> ExecutePayment(string paymentId, string payerId) { var client = PayPalConfiguration.GetClient(); var paymentExecution = new PaymentExecution() { PayerId = payerId }; var payment = new Payment() { Id = paymentId }; PaymentExecuteRequest request = new PaymentExecuteRequest(paymentId); request.RequestBody(paymentExecution); try { //TODO - ASYNC HttpResponse response = await client.Execute(request); var statusCode = response.StatusCode; return(response.Result <Payment>()); } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw httpException; } }
public static async Task <Payment> CreatePayment(string baseUrl, string intent) { var client = PayPalConfiguration.GetClient(); var payment = new Payment() { Intent = intent, // `sale` or `authorize` Payer = new Payer() { PaymentMethod = "paypal" }, Transactions = GetTransactionsList(), RedirectUrls = GetReturnUrls(baseUrl, intent) }; PaymentCreateRequest request = new PaymentCreateRequest(); request.RequestBody(payment); try { //TODO - ASYNC HttpResponse response = await client.Execute(request); var statusCode = response.StatusCode; return(response.Result <Payment>()); } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw httpException; } }
public static async Task <Capture> CapturePayment(string paymentId, string PayerID) { var client = PayPalConfiguration.GetClient(); var payment = await PayPalPaymentService.ExecutePayment(paymentId, PayerID); //https://github.com/paypal/PayPal-NET-SDK/issues/156 var authId = payment .Transactions[0] .RelatedResources[0] .Authorization.Id; AuthorizationCaptureRequest request = new AuthorizationCaptureRequest(authId); // Specify an amount to capture. By setting 'is_final_capture' to true, all remaining funds held by the authorization will be released from the funding instrument. var capture = new Capture() { Amount = new Amount() { Currency = "USD", Total = "4.54" }, IsFinalCapture = true }; request.RequestBody(capture); try { //TODO - ASYNC HttpResponse response = await client.Execute(request); var statusCode = response.StatusCode; return(response.Result <Capture>()); } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw httpException; } }
public static async Task <Agreement> CreateBillingAgreement(string planId, SimplePostalAddress shippingAddress, string name, string description, DateTime startDate) { var client = PayPalConfiguration.GetClient(); var agreement = new Agreement() { Name = name, Description = description, StartDate = startDate.ToString("yyyy-MM-ddTHH:mm:ss") + "Z", Payer = new PayPal.v1.BillingAgreements.Payer() { PaymentMethod = "paypal" }, Plan = new PlanWithId() { Id = planId }, ShippingAddress = shippingAddress }; AgreementCreateRequest request = new AgreementCreateRequest(); request.RequestBody(agreement); request.Body = agreement; try { HttpResponse response = await client.Execute(request); var statusCode = response.StatusCode; return(response.Result <Agreement>()); } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw httpException; } }
public static async Task <Plan> UpdateBillingPlan(string planId, string path, object value) { var client = PayPalConfiguration.GetClient(); var updates = new Plan() { State = "ACTIVE" }; var patch = new PayPal.v1.BillingPlans.JsonPatch <Plan>() { Op = "replace", Path = "/", Value = updates }; PlanUpdateRequest <Plan> request = new PlanUpdateRequest <Plan>(planId); request.RequestBody(new List <PayPal.v1.BillingPlans.JsonPatch <Plan> > { patch }); try { HttpResponse response = await client.Execute(request); var statusCode = response.StatusCode; return(response.Result <Plan>()); } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw httpException; } }
public static async Task <Agreement> ExecuteBillingAgreement(string token) { var client = PayPalConfiguration.GetClient(); AgreementExecuteRequest request = new AgreementExecuteRequest(token); // NOTE: There is a known bug where this endpoint requires an empty JSON body. request.Body = "{}"; try { HttpResponse response = await client.Execute(request); var statusCode = response.StatusCode; return(response.Result <Agreement>()); } catch (HttpException httpException) { var statusCode = httpException.StatusCode; var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw httpException; } }