What could be causing this error with creating an order on Paypal?

Every time I run this code and click the Paypal button, I encounter the following error:

Error: "TypeError: Cannot read property 'map'

Do you have any clue why this is happening? I am pretty sure that I formatted it correctly. (I replaced MY_CLIENT_ID with my actual client ID).

I am assuming that no server-side code is required to support this.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://www.paypal.com/sdk/js?currency=GBP&client-id=MY_CLIENT_ID"></script>
</head>
<body>

<div id="paypal-button-container"></div>

<!-- Add the checkout buttons, set up the order and approve the order -->
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create([{
"purchase_units":{
"reference_id":"HOP_6rN2fD3oyM",
"description":"Hop Music Lesson Purchase",
"custom_id":"HOP_6rN2fD3oyM",
"soft_descriptor":"HOP_6rN2fD3oyM",
"amount":{
"currency_code":"GBP",
"value":"36",
"breakdown":{
"item_total":{"currency_code":"GBP",
"value":"36"}}
},
"items":[{
"name":"Single Lesson, In-Person: 45 mins",
"description":"Single Lesson, In-Person: 45 mins",
"sku":"45MIN_SINGLE_INPERSON",
"unit_amount":{
"currency_code":"GBP",
"value":"36"},
"quantity":"1",
"category":"DIGITAL_GOODS"
}]
}}]);
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container'); // Display payment options on your web page
</script>


</body>
</html>

Answer №1

"genre":"INDIVIDUAL"

It seems that the category mentioned is not valid and could be causing a map error in the system. Take a look at this documentation for more information.

type enum

The type of item category it belongs to can either be:

  • DIGITAL_GOODS. Refers to electronic goods that are transferred digitally.
  • PHYSICAL_GOODS. Indicates tangible items that require physical delivery.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The integrity attribute in the resource for Bootstrap popper.js could not be located

I recently encountered an issue with using the CDN from Bootstrap pages which resulted in errors on all of my Bootstrap pages. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3 ...

Having Trouble with My Loot Table in Fabric 1.15.2

Hi there, I'm new to minecraft Modding and I prefer using fabric because it's more user-friendly. I'm having trouble with the loot table for my block, can anyone help me out? This is the code I have: { "type": "m ...

Updating an array using `setState` does not result in the array being updated

I created a component that uses the .map() method to render an array of students and has a button to shuffle and update the display. However, I'm facing an issue where the display does not update every time I click the button. const Home: NextPage = ...

How can I stop a browser from refreshing when I click the mouse?

After taking steps to prevent the browser back button from functioning by clearing history and disabling key events for page refresh, I am now seeking a way to also stop mouse clicks on the browser's refresh button. Can anyone offer assistance with th ...

tips for selecting various API requests based on the selected drop down menu choice

Hey there! I'm looking to enhance my login page by adding a feature that allows users to select from a dropdown menu with different options. Each option will be linked to a specific API, and based on the API response, the user's ability to log in ...

utilizing YouTube API for real-time updates

Is there a YouTube API equivalent to the HTML5 video's ontimeupdate event that is not documented or known? I have attempted using a setInterval method but it requires additional checks for video play status. Has anyone encountered this problem before? ...

The status of the Ajax response is non-existent

On my local server (jsboss), I have a resource located at: Using the Mozilla RESTClient addon, when I access this URL, I receive the following response: Status Code: 200 OK Content-Length: 160 Content-Type: application/vnd.collection+json Alternatively, ...

Retrieving information from MySQL using javascript

I am trying to fetch data from a MySQL database using JavaScript. This is the script I have used to load the JavaScript: <script type="text/javascript" src="http://www.domain.de/content/entwicklung/layer.js"></script> Here is the actual scri ...

Guide to creating a clean and minimalistic tabbed menu using CSS

Looking for CSS code for the tabbed menu shown above. I've tried several options but haven't been able to achieve the exact design I want. Here is the directive, HTML, and CSS code provided: <div id="tabs"> <ul> <li> ...

Retrieve the innerHtml value of an asp.net Label using C# programmatically

I have a JavaScript function that successfully retrieves the cursor position value. I am assigning this value to an ASP.NET label's innerHTML property. How can I access this innerHTML property when a treeview_selectednodechange event occurs in my prog ...

An HTML form is unable to send data to a JavaScript function via

Creating a web form in HTML for user input and submission, encountering an error when trying to load the submitted data from submitted.html. Error: Cannot POST /api/submitted The code within my index.html file is as shown below: <form action="/a ...

I'm puzzled as to why my Vuex modules are not functioning properly. I keep receiving the error message: "[vuex]

I've been searching for hours and can't figure out why I keep getting this error message: [vuex] unknown mutation type: groceryStore/getStoreApple on all of the commits to the mutations in the groceryStore-module. I believe I'm following the ...

Looking to include a sub element in my menu items using jQuery and CSS

Using jQuery and CSS, I have created a menu item. How can I navigate from one menu item to another sub menu item, as illustrated in the image below? Below is my HTML markup: <link rel="stylesheet" href="css/style_j.css" type="text/css" media="screen"/ ...

One issue with AngularJs is that it does not accurately display data that has been modified within

My MediaService service is being modified within a component. The data in MediaService is connected to another component, but any changes made in the first component are not reflected in the HTML of the second component. MediaService angular .module(&apo ...

What is the method by which frameworks such as Angular encapsulate CSS within a component?

I have a question out of curiosity, rather than seeking a solution to a specific issue. Can you explain how frameworks such as Angular manage to keep CSS contained within a component and prevent it from spreading across the entire webpage? ...

Encountering SCRIPT1014 and SCRIPT1002 errors within an Angular4 application when using Internet Explorer 11

My Angular 4 application runs perfectly in various browsers. However, when trying to launch it in Internet Explorer version 11, I encounter the following two errors: SCRIPT1014: Invalid character addScript.js (9,1) SCRIPT1002: Syntax error main.bundle.js ...

Enhancing Filtering Capabilities with Multiple ng-Model in AngularJS

I am facing an issue with filtering a form based on user input in a text box or selection from a dropdown list. The text box filter works fine individually, but when I try to combine it with the dropdown list selection, neither filter seems to work. Below ...

Issues are arising with the .mouseover functionality within this particular code snippet

Learning Javascript has been a challenge for me so far. I tried following a tutorial, but the result I got wasn't what I expected based on the video. I'm wondering why that is and how I can fix it. I'm aiming to make a box appear suddenly w ...

Traverse through an array of elements within a React component

I will be receiving data from an API and storing it in a state object that appears like the following: constructor(props) { super(props); this.state = { searchable: false, selectValue: 'day-to-day-banking', clearable: false, data: { ...

What is the best way to transfer an array value from PHP to Ajax jQuery?

My code returns statusText: OK, but I am encountering issues retrieving PHP object or array values. I am using Fedora 30 with HTTPd 2.4.39, PHP 7.6, and MySQL 10.3.12. For jQuery, I have the latest version installed. In my PHP file, I have set the content ...