public async Task <InvoicePaymentProvider> UpdateAmountInvoice(InvoicePaymentProvider invoicePaymentProvider, Domain.Entities.Orders.Order order) { PayPalEnvironment environment = CreateEnvironment(); var client = new PayPalHttpClient(environment); var getOrderRequest = new OrdersGetRequest(invoicePaymentProvider.Transaction); try { var getOrderResponse = await client.Execute(getOrderRequest); var getOrderResult = getOrderResponse.Result <PaypalOrder>(); var payment = new OrderRequest() { CheckoutPaymentIntent = "CAPTURE", PurchaseUnits = new List <PurchaseUnitRequest>() { new PurchaseUnitRequest() { CustomId = getOrderResult.PurchaseUnits[0].CustomId, Description = getOrderResult.PurchaseUnits[0].Description, AmountWithBreakdown = new AmountWithBreakdown() { CurrencyCode = Currency.CurrencyValue.USD.ToString(), Value = Convert.ToInt32(order.TotalAmount).ToString() } } }, ApplicationContext = CreateApplicationContext() }; var request = new OrdersCreateRequest(); request.Prefer("return=representation"); request.RequestBody(payment); var response = await client.Execute(request); var result = response.Result <PaypalOrder>(); var uri = new Uri(result.Links.Single(l => l.Rel == "approve").Href); await CancelInvoice(invoicePaymentProvider); invoicePaymentProvider.Link = uri; invoicePaymentProvider.Transaction = result.Id; return(invoicePaymentProvider); } catch (HttpException httpException) { var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw httpException; } }
public async Task <InvoicePaymentProvider> CreateUriForPayment(Invoice invoice, Domain.Entities.Orders.Order order, Plan plan) { PayPalEnvironment environment = CreateEnvironment(); var client = new PayPalHttpClient(environment); var payment = new OrderRequest() { CheckoutPaymentIntent = "CAPTURE", PurchaseUnits = new List <PurchaseUnitRequest>() { new PurchaseUnitRequest() { CustomId = invoice.Id.ToString(), Description = plan.Description, AmountWithBreakdown = new AmountWithBreakdown() { CurrencyCode = Currency.CurrencyValue.USD.ToString(), Value = Convert.ToInt32(plan.PlanPrices.Single(x => x.Currency.Code == Currency.CurrencyValue.USD).Price).ToString() } } }, ApplicationContext = CreateApplicationContext() }; //https://developer.paypal.com/docs/api/orders/v2/#orders_create var request = new OrdersCreateRequest(); request.Prefer("return=representation"); request.RequestBody(payment); try { var response = await client.Execute(request); var result = response.Result <PaypalOrder>(); var uri = new Uri(result.Links.Single(l => l.Rel == "approve").Href); return(new InvoicePaymentProvider { InvoceId = invoice.Id, Link = uri, Transaction = result.Id, PaymentProvider = new PaymentProvider(PaymentProvider.PaymentProviderValue.Paypal) }); } catch (HttpException httpException) { var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault(); throw httpException; } }
public Task <InvoicePaymentProvider> CreateUriForPayment(Invoice invoice, Domain.Entities.Orders.Order order, ProductSale productSale) { throw new NotImplementedException(); }