//private readonly ShoppingCart _shoppingCart; //public PayPalPaymentService(ShoppingCart shoppingCart) //{ // _shoppingCart = shoppingCart; //} public Payment CreatePayment(string baseUrl, string intent, ShoppingCart shoppingCart) { // ### 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(shoppingCart), redirect_urls = GetReturnUrls(baseUrl, intent) }; // Create a payment using a valid APIContext var createdPayment = payment.Create(apiContext); return(createdPayment); }
public 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 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); }