public static Payment CreatePayment(string baseUrl, string intent) { // ### 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 = PayPalConfiguration.GetAPIContext(); // Payment Resource var payment = new Payment() { intent = intent, // `sale` or `authorize` payer = new Payer() { payment_method = "paypal" }, transactions = GetTransactionsList(), redirect_urls = GetReturnUrls(baseUrl, intent) }; // Create a payment using a valid APIContext var createdPayment = payment.Create(apiContext); return(createdPayment); }
public static Plan CreateBillingPlan(string name, string description, string baseUrl) { 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); // PayPal Authentication tokens var apiContext = PayPalConfiguration.GetAPIContext(); // Create plan plan = plan.Create(apiContext); // Activate the plan var patchRequest = new PatchRequest() { new Patch() { op = "replace", path = "/", value = new Plan() { state = "ACTIVE" } } }; plan.Update(apiContext, patchRequest); return(plan); }
public static Agreement CreateBillingAgreement(string planId, ShippingAddress shippingAddress, string name, string description, DateTime startDate) { // PayPal Authentication tokens var apiContext = PayPalConfiguration.GetAPIContext(); var agreement = new Agreement() { name = name, description = description, start_date = startDate.ToString("yyyy-MM-ddTHH:mm:ss") + "Z", payer = new Payer() { payment_method = "paypal" }, plan = new Plan() { id = planId }, shipping_address = shippingAddress }; var createdAgreement = agreement.Create(apiContext); return(createdAgreement); }
public static void ExecuteBillingAgreement(string token) { // PayPal Authentication tokens var apiContext = PayPalConfiguration.GetAPIContext(); var agreement = new Agreement() { token = token }; var executedAgreement = agreement.Execute(apiContext); }
public static void CancelBillingAgreement(string agreementId) { var apiContext = PayPalConfiguration.GetAPIContext(); var agreement = new Agreement() { id = agreementId }; agreement.Cancel(apiContext, new AgreementStateDescriptor() { note = "Cancelling the agreement" }); }
public static void ReactivateBillingAgreement(string agreementId) { var apiContext = PayPalConfiguration.GetAPIContext(); var agreement = new Agreement() { id = agreementId }; agreement.ReActivate(apiContext, new AgreementStateDescriptor() { note = "Reactivating the agreement" }); }
public static void UpdateBillingPlan(string planId, string path, object value) { // PayPal Authentication tokens var apiContext = PayPalConfiguration.GetAPIContext(); // Retrieve Plan var plan = Plan.Get(apiContext, planId); // Activate the plan var patchRequest = new PatchRequest() { new Patch() { op = "replace", // Only the 'replace' operation is supported when updating billing plans. path = path, value = value } }; plan.Update(apiContext, patchRequest); }
public static Payment ExecutePayment(string paymentId, string payerId) { // ### 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 = PayPalConfiguration.GetAPIContext(); var paymentExecution = new PaymentExecution() { payer_id = payerId }; var payment = new Payment() { id = paymentId }; // Execute the payment. var executedPayment = payment.Execute(apiContext, paymentExecution); return(executedPayment); }
public static Capture CapturePayment(string paymentId) { var apiContext = PayPalConfiguration.GetAPIContext(); var payment = Payment.Get(apiContext, paymentId); var auth = payment.transactions[0].related_resources[0].authorization; // 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" }, is_final_capture = true }; // Capture an authorized payment by POSTing to // URI v1/payments/authorization/{authorization_id}/capture var responseCapture = auth.Capture(apiContext, capture); return(responseCapture); }