WooCommerce REST API Edit Customer Downloads - woocommerce

The REST API v2 customers downloads endpoint at:
/wp-json/wc/v2/customers//downloads
is currently read-only. We need the ability to edit the 'Downloads remaining' and 'Access expires' values for individual customer downloads and cannot currently do this via the REST API.
Anyone know another way to edit these values without having to use the WooCommerce Admin page to change these one by one?

Related

woocommerce rest API request for purchase single product

New to woocommerce ,i develop a sale file app , i decide to use woocommerce rest API i can show products
/wc-api/v2/products
I know how can add to order
/wc-api/v2/orders
How can add product to cart and checkout and connect to bank gateway?
The cart is part of a session and is saved in the MySQL table wp_woocommerce_sessions. This table is accessed using a WC_Session_Handler object. AFAIK the WooCommerce REST API does not provide access to WC_Session_Handler objects.
I don't understand exactly what you are trying to do but if you want to access the cart through the REST API I think you will need to implement your own REST controller for the wp_woocommerce_sessions table. This isn't that difficult to do as you can modify one of the existing WooCommerce REST controllers to work with WC_Session_Handler objects to access the wp_woocommerce_sessions table.
But, beware a WooCommerce session is bound to a browser session through cookies and you need to handle that binding.

Google Forms PayPal Express Integration

I am doing work for a non profit with 0 budget for IT. They need to allow users to enter information on a Google Form and then collect payment. I have done a lot of research on the topic and currently appears you can only add a hyperlink on the Google Forms to link to PayPal. However, I was wondering if there was some way to link the PayPal Express Checkout javascript(https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/add-paypal-button/) into the Google Form so it calls back with a transaction id and status. Then I would be able to somehow insert those values into the Google Form. Any thoughts on how to integrate would be helpful. I am a developer but not familiar with Google Forms.
I recently wrestled with this exact question and ended up building a G Suite addon to make this easier for others. Coincidentally I also do volunteer IT for a small nonprofit and we wanted to use PayPal with our signup form (there's pricing for the addon but just ping me if you're a small nonprofit).
Here's what I learned while building it:
There's no way for Apps Script to modify the form once it's shown to the user, or to use Apps Script to respond to user input
There's no way to redirect the user automatically to PayPal after a form is submitted
That means if you want to send someone to PayPal, you've got to use an ordinary link. You can do this within the form by adding the URL to a question description, or you can add the URL to the text shown once someone has submitted the form. For PayPal, you've got two options for this kind of link:
PayPal buttons
Express checkout
PayPal buttons are a static link managed by PayPal. They don't require any coding - just go here and create a button. Then you need to get the raw text link for the button, which PayPal calls the "email" version. You can insert that into your form directly and tell users to access it. The one problem is there's no real way to get the transaction ID. You could try correlating the form submit time with the payment time, or the payer email with the form submit email. It's possible that neither of them will match up and you'll have to do it manually.
Express checkout requires you to dynamically create a new link for each payment by calling the PayPal API. That means your link needs to open a page that then generates an express checkout URL and redirects the user to it. You can do this using a web app in Google Apps Script using a doGet() trigger, or you can create your backend on your server in any language.
If you can run your own server somewhere, I recommend that (plenty of PaaS services have a free tier). It's much easier to test and debug things when you aren't using Apps Script. I used the PayPal Node SDK which works great despite being unmaintained. (Express checkout is "deprecated" by PayPal, but I'll bet it's not going away anytime soon). Their example will get you most of the way there. When the user arrives, generate a payment link and redirect them. When they finish they'll return to your server, and you can display whatever you want. For example, you can ask them to copy the transaction ID and paste it into your form.
Finally, when your form is submitted an onSubmit() trigger can be set up. There are actually two kinds of onSubmit() triggers for forms - one for the form itself, and a second for the spreadsheet linked to the form. You can register a trigger to do extra processing (e.g. look up the transaction ID), but you can't modify the response in the trigger. You can however modify the spreadsheet where the trigger gets sent, which for most cases is equivalent. For example, you could add a column to the spreadsheet with a link to the PayPal transaction based on the transaction code.

React + Wordpress + Woocommerce REST API 401 - get products without AUTH

I am building a webshop with React, Wordpress v4 and Woocommerce Rest api v2.
I am a bit confused on how to proceed with authentication. I understand that for some requests like place an order or create a new product I need to authenticate.
But I also need to be able to just retrieve all products for a customer who visits the site for the first time and just wants to browse through all our products.
What is the best practice here?
My thoughts are:
Create a public, separate layer with PHP or Node which securely stores the Woocommerce API keys and provides public endpoints (only GET, i.e. GET /products)
Access those endpoints via JS/React and render the products
Create another separate layer for placing orders which requires the costumer to authenticate (i.e. POST /orders)
Also, instead of adding a separate layer I could use the Wordpress function add_action( 'rest_api_init',...
Is there a better way to do it or am I missing something? Or can I retrieve the Woocommerce Products somehow via the Wordpress API endpoints without api keys?
Okay, somehow I was thinking the wrong way. As wordpress lists all products which were created in woocommerce as a regular Wordpress post with post-type product, I just have to make a request to the Wordpress API (NOT the Woocommerce API!), in my example:
http://laflor.wordpress.local/wp-json/wp/v2/product

Add user on UrBackup server after order on Woocommerce site

I have wordpress site with woocommerce shop and I’m selling among others UrBackup client accounts on my server.
Do you have any idea how to automatically add UrBackup user after order in woocommerce?
Or maybe easier will be create shop based on different engine?
Any advice, tips? :)
After poking around a bit, it looks like UrBackup has an API you can use, that most likely has a 'create account' endpoint. I didn't see it immediately in their not-so-great documentation, but you'd think it'd HAVE to be there somewhere! There's also a PHP API kit you could integrate into your WordPress site here:
https://bitbucket.org/opensaucesystemsdevelopment/urbackup-api.git
So, you could load in this class, and after a WooCommerce order is placed, call the API endpoint to create a user. To do this with WooCommerce, you'd need to create a function on the "woocommerce_order_status_completed" hook.
http://hookr.io/actions/woocommerce_order_status_completed/
This would let you run any custom code you'd like after an order's payment has completed. Thus, you could check an order for if it contains the UrBackup product, and if so call the UrBackup API to create an account based on the current user's data.
Should work!

paypal Payments Pro Hosted Solution Integration repeat payment

I am using paypal express checkout where i can create take payment for an order with multiple recurring payment profiles in it. e.g. initial payment £5, item A £3 every month, item B £5 every year.
I am asked to implement this using website payments pro hosted solution using iframe API now.
But i can't figure out how to pass this order to it.
According to Integration guide I need to use Button Manager API and create a template= templateD button type, but that button type only accept one profile.
https://www.paypalobjects.com/webstatic/en_GB/developer/docs/pdf/hostedsolution_uk.pdf
you cannot create a recurring profile through the Hosted Payments endpoint by passing "Payments Standards" variables.
The PayPal system will automatically do a 302 redirect to the webscr endpoint (if the browser were to load the page outside of the iframe, with X-Frame-Options set, it refuses to load at all).
You cannot create recurring payments profiles through HSS (hosted sole solution). This product will merely take credit card payments from your site.

Resources