Search code examples
c#.netpaypalpaypal-subscriptions

PayPal product creation using .net


I am trying to intagrate PayPal in my application. I want to create product but there is no .net sdk available for it. I want to integrate it in asp.net core web application. I have gone through documentation is there any other way to create subscriptions. For subscription I have to first create product and then plan. I don't have any code because I am confused. I am using following link

Reference Link


Solution

  • As there are no SDKs for the current Subscriptions APIs, use a direct HTTP integration. Here is a sample in C# with HttpClient:

    using (var httpClient = new HttpClient())
    {
        using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api-m.sandbox.paypal.com/v1/catalogs/products"))
        {
            request.Headers.TryAddWithoutValidation("Authorization", "Bearer <Access-Token>");
            request.Headers.TryAddWithoutValidation("PayPal-Request-Id", "PRODUCT-18062020-001"); 
    
            request.Content = new StringContent("{\n  \"name\": \"Service Name\",\n  \"description\": \"Description\",\n  \"type\": \"SERVICE\",\n  \"category\": \"SOFTWARE\",\n}");
            request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); 
    
            var response = await httpClient.SendAsync(request);
        }
    }
    

    Products and plans can also be managed manually in the web interface