Added login request
This commit is contained in:
5
woocomerce-order/package-lock.json
generated
5
woocomerce-order/package-lock.json
generated
@@ -1307,6 +1307,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"base-64": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/base-64/-/base-64-0.1.0.tgz",
|
||||
"integrity": "sha1-eAqZyE59YAJgNhURxId2E78k9rs="
|
||||
},
|
||||
"base64-js": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz",
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"babel-loader": "7.1.2",
|
||||
"babel-preset-react-app": "^3.1.1",
|
||||
"babel-runtime": "6.26.0",
|
||||
"base-64": "^0.1.0",
|
||||
"case-sensitive-paths-webpack-plugin": "2.1.1",
|
||||
"chalk": "1.1.3",
|
||||
"cross-fetch": "^2.2.1",
|
||||
|
||||
@@ -1,19 +1,41 @@
|
||||
import React, { Component } from 'react';
|
||||
import './App.css';
|
||||
import { Order } from './components';
|
||||
import { sendOrder } from './actions';
|
||||
import Wiass from './components';
|
||||
import { sendOrder, logIn } from './actions';
|
||||
|
||||
|
||||
const onOrderClicked = function () {
|
||||
return sendOrder()
|
||||
}
|
||||
|
||||
class App extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {roles: []};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
render() {
|
||||
let self = this
|
||||
const authentucate = function (username, password) {
|
||||
logIn(username, password).then(response => {
|
||||
self.setState((prevState, props) => {
|
||||
return {roles: JSON.stringify(response.roles)};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const onLogInClicked = function (username, password) {
|
||||
return authentucate(username, password)
|
||||
}
|
||||
|
||||
const onOrderClicked = function () {
|
||||
return sendOrder()
|
||||
}
|
||||
return (
|
||||
<div className="App">
|
||||
<Order onOrderClicked={onOrderClicked} />
|
||||
{this.state.roles}
|
||||
<Wiass onOrderClicked={onOrderClicked} onLogInClicked={onLogInClicked} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,57 +1,82 @@
|
||||
import fetch from 'cross-fetch'
|
||||
var WooCommerceAPI = require('woocommerce-api');
|
||||
var Base64 = require('base-64');
|
||||
|
||||
|
||||
export const SEND_ORDER = 'SEND_ORDER'
|
||||
|
||||
var WooCommerce = new WooCommerceAPI({
|
||||
url: 'https://localhost',
|
||||
consumerKey: 'ck_79837fb6f49f9f3eca830e34faeeea35b6cc1287',
|
||||
consumerSecret: 'cs_18bd03a0e6afd7d5c9e51e1d1c86032e425bd8d8',
|
||||
wpAPI: true,
|
||||
version: 'wc/v2',
|
||||
url: 'https://localhost',
|
||||
consumerKey: 'ck_79837fb6f49f9f3eca830e34faeeea35b6cc1287',
|
||||
consumerSecret: 'cs_18bd03a0e6afd7d5c9e51e1d1c86032e425bd8d8',
|
||||
wpAPI: true,
|
||||
version: 'wc/v2',
|
||||
});
|
||||
|
||||
export function sendOrder() {
|
||||
|
||||
var data = {
|
||||
payment_method: 'bacs',
|
||||
payment_method_title: 'Direct Bank Transfer',
|
||||
set_paid: true,
|
||||
billing: {
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
address_1: '969 Market',
|
||||
address_2: '',
|
||||
city: 'San Francisco',
|
||||
state: 'CA',
|
||||
postcode: '94103',
|
||||
country: 'US',
|
||||
email: 'john.doe@example.com',
|
||||
phone: '(555) 555-5555'
|
||||
},
|
||||
shipping: {
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
address_1: '969 Market',
|
||||
address_2: '',
|
||||
city: 'San Francisco',
|
||||
state: 'CA',
|
||||
postcode: '94103',
|
||||
country: 'US'
|
||||
},
|
||||
line_items: [
|
||||
{
|
||||
product_id: 93,
|
||||
quantity: 2
|
||||
},
|
||||
{
|
||||
product_id: 22,
|
||||
variation_id: 23,
|
||||
quantity: 1
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
WooCommerce.post('orders', data, function(err, data, res) {
|
||||
console.log(res);
|
||||
});
|
||||
}
|
||||
var data = {
|
||||
payment_method: 'bacs',
|
||||
payment_method_title: 'Direct Bank Transfer',
|
||||
set_paid: true,
|
||||
billing: {
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
address_1: '969 Market',
|
||||
address_2: '',
|
||||
city: 'San Francisco',
|
||||
state: 'CA',
|
||||
postcode: '94103',
|
||||
country: 'US',
|
||||
email: 'john.doe@example.com',
|
||||
phone: '(555) 555-5555'
|
||||
},
|
||||
shipping: {
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
address_1: '969 Market',
|
||||
address_2: '',
|
||||
city: 'San Francisco',
|
||||
state: 'CA',
|
||||
postcode: '94103',
|
||||
country: 'US'
|
||||
},
|
||||
line_items: [
|
||||
{
|
||||
product_id: 93,
|
||||
quantity: 2
|
||||
},
|
||||
{
|
||||
product_id: 22,
|
||||
variation_id: 23,
|
||||
quantity: 1
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
WooCommerce.post('orders', data, function (err, data, res) {
|
||||
console.log(res);
|
||||
});
|
||||
}
|
||||
|
||||
export function logIn(username, password) {
|
||||
|
||||
let auth = Base64.encode(username + ':' + password)
|
||||
let fullPath = 'https://localhost/wp-json/wiaas/v1/user'
|
||||
return fetch(fullPath, {
|
||||
method: 'get',
|
||||
headers: {
|
||||
'authorization': 'Basic ' + auth
|
||||
}
|
||||
}).then(response => {
|
||||
switch (response.status) {
|
||||
case 401:
|
||||
console.log(response.code)
|
||||
break
|
||||
case 200:
|
||||
return response.json()
|
||||
default:
|
||||
console.log(response.code)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import React from 'react'
|
||||
import Order from './order'
|
||||
import Login from './login'
|
||||
|
||||
export const Order = (props) => {
|
||||
export const Wiaas = (props) => {
|
||||
|
||||
return (
|
||||
<button onClick={props.onOrderClicked} > SEND ORDER </button>
|
||||
<div>
|
||||
<Login onLogInClicked={props.onLogInClicked}/>
|
||||
<Order onOrderClicked={props.onOrderClicked} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Order
|
||||
export default Wiaas
|
||||
24
woocomerce-order/src/components/login/index.js
Normal file
24
woocomerce-order/src/components/login/index.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import React from 'react'
|
||||
|
||||
export const Login = (props) => {
|
||||
|
||||
let username = ""
|
||||
let password = ""
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<label > USERNAME </label>
|
||||
<input ref={el => username=el} type="text" />
|
||||
</div>
|
||||
<div>
|
||||
<label > PASSWORD </label>
|
||||
<input ref={el => password=el} type="password" />
|
||||
</div>
|
||||
<button onClick={() => props.onLogInClicked(username.value, password.value)}> SIGN IN </button>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Login
|
||||
10
woocomerce-order/src/components/order/index.js
Normal file
10
woocomerce-order/src/components/order/index.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
|
||||
export const Order = (props) => {
|
||||
|
||||
return (
|
||||
<button onClick={props.onOrderClicked} > SEND ORDER </button>
|
||||
)
|
||||
}
|
||||
|
||||
export default Order
|
||||
Reference in New Issue
Block a user