Code

Discussion on PayPal Checkout in ASP.NET Web Forms & C#, Using Orders v2 REST API, Server-side Integration

Discussion on PayPal Checkout in ASP.NET Web Forms & C#, Using Orders v2 REST API, Server-side Integration

Cart 32 sales

Techtolia supports this item

Supported

This author's response time can be up to 2 business days.

11 comments found.

everything is working well, but I can’t change from Load_Page UnitAmount and etc. I tried to use different options – yours and others – the result is zero

OrderRequest.PurchaseUnits.Add(new PurchaseUnitRequest { ReferenceId = “ReferenceId1”, Description = “Description1”, CustomId = “CustomId1”, SoftDescriptor = “SoftDescriptor1”, AmountWithBreakdown = new AmountWithBreakdown { CurrencyCode = “USD”, Value = “280”, AmountBreakdown = new AmountBreakdown { ItemTotal = new Money { CurrencyCode = “USD”, Value = “1.00” }, Shipping = new Money { CurrencyCode = “USD”, Value = “1.00” }, Handling = new Money { CurrencyCode = “USD”, Value = “1.00” }, TaxTotal = new Money { CurrencyCode = “usd”, Value = “1.00” }, ShippingDiscount = new Money { CurrencyCode = “USD”, Value = “1.00” } } } , Items = new List<Item> { new Item { Category = “PHYSICAL_GOODS”, Description = “Product 1 Description”, Name = “Product 1”, Quantity = “1”, Sku = “Sku1”, Tax = new Money {CurrencyCode = “USD”, Value = “15”}, UnitAmount = new Money {CurrencyCode = “USD”, Value = “280”} } } });

your variant

OrderRequest.PurchaseUnits[0].Items.Add(new Item()
           {
               Category = "PHYSICAL_GOODS", 
               Description = "Product 1 Description", 
               Name = "Product 1", 
               Quantity = "1", 
               Sku = "Sku2", 
               Tax = new Money { CurrencyCode = "usd", Value = "15" }, 
               UnitAmount = new Money { CurrencyCode = "usd", Value = "280" }
})

next variant

OrderRequest.PurchaseUnits.Add(new PurchaseUnitRequest { ReferenceId = “ReferenceId1”, Description = “Description1”, CustomId = “CustomId1”, SoftDescriptor = “SoftDescriptor1”, AmountWithBreakdown = new AmountWithBreakdown { CurrencyCode = ””, Value = ””, AmountBreakdown = new AmountBreakdown { ItemTotal = new Money { CurrencyCode = “usd”, Value = “1.00” }, Shipping = new Money { CurrencyCode = “usd”, Value = “1.00” }, Handling = new Money { CurrencyCode = “usd”, Value = “1.00” }, TaxTotal = new Money { CurrencyCode = “usd”, Value = “1.00” }, ShippingDiscount = new Money { CurrencyCode = “usd”, Value = “1.00” } }} });

and other variant

OrderRequest.PurchaseUnits.Add(new PurchaseUnitRequest { ReferenceId = “ReferenceId1”, Description = “Description1”, CustomId = “CustomId1”, SoftDescriptor = “SoftDescriptor1”, AmountWithBreakdown = new AmountWithBreakdown { CurrencyCode = “650”, Value = “usd”, AmountBreakdown = new AmountBreakdown { ItemTotal = new Money { CurrencyCode = “usd”, Value = “1.00” }, Shipping = new Money { CurrencyCode = “usd”, Value = “1.00” }, Handling = new Money { CurrencyCode = “usd”, Value = “1.00” }, TaxTotal = new Money { CurrencyCode = “usd”, Value = “1.00” }, ShippingDiscount = new Money { CurrencyCode = “usd”, Value = “1.00” } } } });

Hi AnatoliD,

Thanks for reaching out. Hope you’re keeping well!

First of all, you should delete the new Item in the orderRequest Items list:

new Item
{
Name = "Product 1",
Description = "Product 1 Description",
Sku = "Sku1",
UnitAmount = new Money
{
CurrencyCode = Currency,
Value = "90.00" 
},
Tax = new Money
{
CurrencyCode = Currency,
Value = "10.00" 
},
Quantity = "1",
Category = "PHYSICAL_GOODS" 
},                       

Next, use the code sample below and right click on your project name and do Build/Rebuild your project

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
orderRequest.PurchaseUnits[0].Items.Add(new Item()
{
Category = "PHYSICAL_GOODS",
Description = "Product 1 Description",
Name = "Product 1",
Quantity = "1",
Sku = "Sku2",
Tax = new Money { CurrencyCode = Currency, Value = "15.00" },
UnitAmount = new Money { CurrencyCode = Currency, Value = "280.00" }
});
                orderRequest.PurchaseUnits[0].AmountWithBreakdown.Value = "305.00";
                orderRequest.PurchaseUnits[0].AmountWithBreakdown.AmountBreakdown.ItemTotal.Value = "280.00";
                orderRequest.PurchaseUnits[0].AmountWithBreakdown.AmountBreakdown.TaxTotal.Value = "15.00";
}            
}

In the meantime if you have any other questions, let us know and we’ll be happy to help!

hello@techtolia.com

Great job and very fast support. Highly recommend!!! Thank you very much – you saved a lot of time

You are welcome, we are so glad to hear that you had a good product and experience.

Hello We have bought your code.

how we can change the Intent option from capture to authorized ?

we have tried to update the value in Checkout.ascx ,but we are getting error

click_initiate_payment_reject

please update us ASAP

thanks

Hi ahmwai,

Thanks for reaching out. Hope you’re keeping well!

In our code createOrder and onApprove functions are added for the buttons to work:
- createOrder is called when the buyer clicks on one of the payment buttons. This function must return an order ID to render the checkout flow. createOrder calls your server to get the order ID.
- onApprove is called when the buyer approves the order. This happens when the buyer successfully completes the checkout flow. onApprove calls your server to make a capture order call.

If you want to Authorize only,
1- update onApprove (in Checkout.ascx) to: onApprove: function (data, actions) { $("#Progress").show(); $("#ProgressBackground").show(); actions.order.authorize().then(function (authorization) { // Get the authorization id var authorizationID = authorization.purchase_units[0].payments.authorizations[0].id scrollToTop(); $("#Progress").hide(); $("#ProgressBackground").hide() mainElement.className = "success"; document.getElementById('pOrder').innerText = "Authorization ID : " + authorizationID; }); },
2- update the src (in Checkout.ascx) to <script src="https://www.paypal.com/sdk/js?client-id=<%=ClientId%>&components=buttons,funding-eligibility&intent=authorize"></script>
3- update CheckoutPaymentIntent (in Checkout.ascx.cs) to CheckoutPaymentIntent = "AUTHORIZE",
Information:
CAPTURE: The merchant intends to capture payment immediately after the customer makes a payment.
AUTHORIZE: The merchant intends to authorize a payment and place funds on hold after the customer makes a payment. Authorized payments are best captured within three days of authorization but are available to capture for up to 29 days. After the three-day honor period, the original authorized payment expires and you must re-authorize the payment. You must make a separate request to capture payments on demand. This intent is not supported when you have more than one `purchase_unit` within your order.


If you need customization or custom web development, please send your needs details with Your Name – Your Company Info – Contact Info – Your Budget to hello@techtolia.com and one of our well established development partners will get back to you with a free quote.


Buy Me A Coffee

Hello

We have uodate the code as you mentioned, now the thank you page showing and there is authorization id, but nothing showing at PayPal dashboard for both the merchant account and the buyer account, the authorization not exists !!.

Please advise what the issue in your code, or make a working example for the authorization and send us, as we already tried many times , even our developers , but we always not getting any trx in our sandbox paypal

Hi ahmwai,

You can test with one of Sample Sandbox Buyer Credentials (https://techtolia.com/PayPal/FaqSupport/) and check it on its dashboard (https://www.sandbox.paypal.com/us/signin).

Our code works,

Item support includes: - Availability of the author to answer questions - Get assistance with reported bugs and issues - Help with included 3rd party assets

If you need customization or custom web development, please send your needs details with Your Name – Your Company Info – Contact Info – Your Budget to hello@techtolia.com and one of our well established development partners will get back to you with a free quote.

The payment and processing works great, but how do you add refunds to this?

Hi arachai,

Thanks for reaching out. Hope you’re keeping well!

If you need customization or custom web development, please send your needs details with Your Name – Your Company Info – Contact Info – Your Budget to hello@techtolia.com and one of our well established development partners will get back to you with a free quote.

After thinking about it for around a week I finally purchased this only for the source code to not work! I built the project and viewed it on my localhost; as soon as you press the any of the Pay Buttons the window opens, immediately closes and then gives the “OOPS Payment failed”!! I changed the client id and secret id in the web config to mine before I even built it. Should I contact support?

Hi arachai,

Thanks for reaching out. Hope you’re keeping well!

Could you please retest it with the following steps 1- download the file from CodeCanyon, rename it to a shorter name, extract folders 2- open folder PayPal, double click PayPal.sln (opens in MS Visual Studio) 3- change the client id and secret id in the web.config to yours 4- right click to Default.aspx, select View in Browser (Google Chrome) 5- test a checkout

If you still get an error: Could you please share the error details on your Console Panel (To open Chrome Console Panel, right click to the page → select Inspect (Ctrl+Shift+I) → select Console Tab).

support@techtolia.com

Thank you very much for the fast response! I ended up testing it when I got home tonight and found that I needed to update my registry for TLS 1.2 (I’m on a Windows 7 machine); as soon as I did that it works perfectly!! This integration saved me the hours I had spent trying to code this myself! I couldn’t be happier!

You are welcome, thank you for your purchase and for your contribution. We’re so glad you had a good product and experience.

I don’t know how to populate the list within the list.

I need to be able to populate a list of items depending on how many items I have, but I keep getting errors.

Thanks in advance. Here is the code.

```

public OrderRequest orderRequest = new OrderRequest()
{
    CheckoutPaymentIntent = "CAPTURE",
};
ApplicationContext = new ApplicationContext
{
    BrandName = "EXAMPLE INC",
    LandingPage = "BILLING",
    CancelUrl = "https://www.example.com",
    ReturnUrl = "https://www.example.com",
    UserAction = "CONTINUE",
    ShippingPreference = "SET_PROVIDED_ADDRESS" 
},
PurchaseUnits = new List<PurchaseUnitRequest>
{
    new PurchaseUnitRequest
    {
        ReferenceId =  "ReferenceId1",
        Description = "Description1",
        CustomId = "CustomId1",
        SoftDescriptor = "SoftDescriptor1",
        AmountWithBreakdown = new AmountWithBreakdown
        {
            CurrencyCode = Currency,
            Value = "110.00",
            AmountBreakdown = new AmountBreakdown
            {
                ItemTotal = new Money
                {
                    CurrencyCode = Currency,
                    Value = "90.00" 
                },
                Shipping = new Money
                {
                    CurrencyCode = Currency,
                    Value = "15.00" 
                },
                Handling = new Money
                {
                    CurrencyCode = Currency,
                    Value = "5.00" 
                },
                TaxTotal = new Money
                {
                    CurrencyCode = Currency,
                    Value = "10.00" 
                },
                ShippingDiscount = new Money
                {
                    CurrencyCode = Currency,
                    Value = "10.00" 
                }
            }
        },
        Items = new List<Item>
        {
            new Item
            {
                Name = "Product 1",
                Description = "Product 1 Description",
                Sku = "Sku1",
                UnitAmount = new Money
                {
                    CurrencyCode = Currency,
                    Value = "90.00" 
                },
                Tax = new Money
                {
                    CurrencyCode = Currency,
                    Value = "10.00" 
                },
                Quantity = "1",
                Category = "PHYSICAL_GOODS" 
            },
        },
}
}

public OrderRequest cardOrderRequest = new OrderRequest();

cardOrderRequest.ApplicationContext.BrandName = “Example INC”;

cardOrderRequest.PurchaseUnits.Add(new PurchaseUnitRequest { ReferenceId = “ReferenceId1”, Description = “Description1”, CustomId = “CustomId1”, SoftDescriptor = “SoftDescriptor1”, AmountWithBreakdown = new AmountWithBreakdown { CurrencyCode = ””, Value = ””, AmountBreakdown = new AmountBreakdown { ItemTotal = new Money { CurrencyCode = “usd”, Value = “1.00” }, Shipping = new Money { CurrencyCode = “usd”, Value = “1.00” }, Handling = new Money { CurrencyCode = “usd”, Value = “1.00” }, TaxTotal = new Money { CurrencyCode = “usd”, Value = “1.00” }, ShippingDiscount = new Money { CurrencyCode = “usd”, Value = “1.00” } }} });

```

But how do I populate the list called ‘Items’. ‘Items = new List<Item>’

I know this information should be within a for loop, depending on how many items. Everything I try I get an error.

Many Thanks if you can help.

Here is what I tried with the error.

```

cardOrderRequest.PurchaseUnits.Add(new PurchaseUnitRequest { new Item { Category = "", Description = "", Name = "", Quantity = "", Sku = "", Tax = new Money { CurrencyCode = "usd", value = "0" }, UnitAmount = new Money { CurrencyCode = "usd", Value = "0" }}});

``` And I get the following error

Cannot initialise type ‘PurchaseUnitRequest’ with a collection initialiser because it does not implement ‘System.Collections.IEnumerable’

Hi barbadose2gmailcom,

Thanks for reaching out. Hope you’re keeping well!

You can use this sample in Page_Load, orderRequest.PurchaseUnits[0].Items.Add(new Item { Category = "", Description = "", Name = "", Quantity = "", Sku = "", Tax = new Money { CurrencyCode = "usd", Value = "0" }, UnitAmount = new Money { CurrencyCode = "usd", Value = "0" } });


In the frontend (in Order Summary and Javascript), please do not forget to create a loop for items.

If you need customization or custom web development, please send your project details with Your Name – Your Company Info – Contact Info – Your Budget to hello@techtolia.com and one of our well established development partners will get back to you with a free quote.

it is possible to fill in the address form from the database

Hi tneuber, thank you for your interest, hope you’re well!

Yes, it is possible, you need to customize the application for your model.

*Full source code is included.

In the meantime if you have any other questions, let us know and we’ll be happy to help!

hello@techtolia.com

Hi, I bought this payment code for our xamarin app. The purchase code is: 5403ad06-10b1-XXXX

How can I set the payment currency to euro. When I change public static string Currency = “USD”; to public static string Currency = “EUR”;

then the page is crashing. Regards Andreas

Hi Andreas, the product is a checkout app, does not include abonnements payment. You need to customize it for your model.

If you need customization for this product, please send the details with Your Name – Your Company Info – Contact Info – Your Budget to hello@techtolia.com and one of our well established development partners will get back to you with a free quote.

Ok, I send you the email with the requirements. Regards Andreas

Thank you for your email. We’re looking forward the new partnership.

Hello,

does it have use case cover for split payment, like if its a multi vendor store and Customer purchase one item from Vendor A, one item from Vendor B

so when customer pays through paypal so amount can be split between vendor A and Vendor B account.

Hi amtechnology, thank you for your interest, hope you’re well!

Unfortunetelly, this product does not have any use case for split payments; however, you may customize it.

Hello I am interested in buying it but I have a couple of questions

1) can I load the Dynamic Price from a database 2) is it in MVC? 3) How difficult is it to implement that code to a website that we need only that part 4) in case we decide to help us implement it or guide us?

Hi eleveth, thank you for your interest, hope you’re well!

1- Yes, the price is set in the Checkout.ascx.cs file (backend), you need to customize it for your model to dynamically determine the price. 2- This is an ASP.NET Web Forms application that requires .NET Framework. 3- There should be a competent .Net developer in your team. 4- Item support does not include:customizations and installations If you need customization or custom web development, please send your project details with Your Name – Your Company Info – Contact Info – Your Budget to hello@techtolia.com and one of our well established development partners will get back to you with a free quote.

Hi eleveth, it is now available for ASP.NET Core MVC. You can purchase it on:

Hola estoy interesado en comprarlo pero tengo un par de preguntas

1) puedo cargar los Precio Dinamico desde una base de datos 2) esta en MVC? 3) que tan dificil esta para implementar ese codigo a una web q necesitamos solo esa parte 4) en caso q decidamos nos ayudar a implementarlo o nos guian?

Hi eleveth, thank you for your interest, hope you’re well!

1- Yes, the price is set in the Checkout.ascx.cs file (backend), you need to customize it for your model to dynamically determine the price. 2- This is an ASP.NET Web Forms application that requires .NET Framework. 3- There should be a competent .Net developer in your team. 4- Item support does not include:customizations and installations If you need customization or custom web development, please send your project details with Your Name – Your Company Info – Contact Info – Your Budget to hello@techtolia.com and one of our well established development partners will get back to you with a free quote.

Hi eleveth, it is now available for ASP.NET Core MVC. You can purchase it on:

this script works on linux server

Hi sanslr, thank you for your interest, hope you’re well!

This is an ASP.NET Web Forms application that requires .NET Framework and runs on Windows.

Info: - https://dotnet.microsoft.com/download

Hi sanslr, it is now available for ASP.NET Core MVC. You can purchase it on:

by
by
by
by
by
by

Tell us what you think!

We'd like to ask you a few questions to help improve CodeCanyon.

Sure, take me to the survey