API & Project Structure

Last updated 4 months ago

This section clarify some API that use from the product, this is base on the Dokan API and some extra customize Wordpress site

Project Structure

  • App/Common folders

    • Config.js: main config variables for the app

    • Colors.js: config theme color for the app

    • Constants.js: Config wordpress URL, icons, categories...

    • Images.js: list of all images use for the app

    • Languages.js: main language file config

    • Layout.js: Use to config the main flexible homepage.

    • Tools: Common functions

  • src/Components: Common components that could be used many time, this could be a custom button, comment component, icon input...

  • src/Containers: most components of the app is putting here, you could change or re-structure by matching with your own project design.

  • src/Expo: Wrapper Expo function

  • src/Services: The Wodpress Api for the app you can refer to the Wordpress API -http://v2.wp-api.org/and custom your own function if you want to add more feature for the app.

  • src/Redux: Main action and reducer

  • src/Navigation: Wrapper function for react-nativigation v2.0

Debug app with Reacttotron

Link download on desktop: http://bit.ly/2L0R9gY

It's already configed with the project, after installed the Reacttotron you can see list of Log, Image, connection, API, Redux actions....

You can able to the config the app to work with Reactotron or React Native Debugger by change useReactotron:false (file common/Constants.js)

get
Get Products

https://your-hosting.com
/wp-json/wc/v2/products
This endpoint allows you to get list of products, detail from - http://bit.ly/2L3vvJi
Request
Response
Query Parameters
page
optional
number
Current page of the collection. Default is 1.
per_page
optional
number
Maximum number of items to be returned in result set. Default is 10.
200: OK
Cake successfully retrieved.
[
{
"id": 799,
"name": "Ship Your Idea",
"slug": "ship-your-idea-22",
"permalink": "https://example.com/product/ship-your-idea-22/",
"date_created": "2017-03-23T17:03:12",
"date_created_gmt": "2017-03-23T20:03:12",
"date_modified": "2017-03-23T17:03:12",
"date_modified_gmt": "2017-03-23T20:03:12",
"type": "variable",
"status": "publish",
"featured": false,
"catalog_visibility": "visible",
"description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>\n",
"short_description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>\n",
"sku": "",
"price": "",
"regular_price": "",
"sale_price": "",
"date_on_sale_from": null,
"date_on_sale_from_gmt": null,
"date_on_sale_to": null,
"date_on_sale_to_gmt": null,
"price_html": "",
"on_sale": false,
"purchasable": false,
"total_sales": 0,
"virtual": false,
"downloadable": false,
"downloads": [],
"download_limit": -1,
"download_expiry": -1,
"external_url": "",
"button_text": "",
"tax_status": "taxable",
"tax_class": "",
"manage_stock": false,
"stock_quantity": null,
"in_stock": true,
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"sold_individually": false,
"weight": "",
"dimensions": {
"length": "",
"width": "",
"height": ""
},
"shipping_required": true,
"shipping_taxable": true,
"shipping_class": "",
"shipping_class_id": 0,
"reviews_allowed": true,
"average_rating": "0.00",
"rating_count": 0,
"related_ids": [
31,
22,
369,
414,
56
],
"upsell_ids": [],
"cross_sell_ids": [],
"parent_id": 0,
"purchase_note": "",
"categories": [
{
"id": 9,
"name": "Clothing",
"slug": "clothing"
},
{
"id": 14,
"name": "T-shirts",
"slug": "t-shirts"
}
],
"tags": [],
"images": [
{
"id": 795,
"date_created": "2017-03-23T14:03:08",
"date_created_gmt": "2017-03-23T20:03:08",
"date_modified": "2017-03-23T14:03:08",
"date_modified_gmt": "2017-03-23T20:03:08",
"src": "https://example.com/wp-content/uploads/2017/03/T_4_front-11.jpg",
"name": "",
"alt": "",
"position": 0
},
{
"id": 796,
"date_created": "2017-03-23T14:03:09",
"date_created_gmt": "2017-03-23T20:03:09",
"date_modified": "2017-03-23T14:03:09",
"date_modified_gmt": "2017-03-23T20:03:09",
"src": "https://example.com/wp-content/uploads/2017/03/T_4_back-10.jpg",
"name": "",
"alt": "",
"position": 1
},
{
"id": 797,
"date_created": "2017-03-23T14:03:10",
"date_created_gmt": "2017-03-23T20:03:10",
"date_modified": "2017-03-23T14:03:10",
"date_modified_gmt": "2017-03-23T20:03:10",
"src": "https://example.com/wp-content/uploads/2017/03/T_3_front-10.jpg",
"name": "",
"alt": "",
"position": 2
},
{
"id": 798,
"date_created": "2017-03-23T14:03:11",
"date_created_gmt": "2017-03-23T20:03:11",
"date_modified": "2017-03-23T14:03:11",
"date_modified_gmt": "2017-03-23T20:03:11",
"src": "https://example.com/wp-content/uploads/2017/03/T_3_back-10.jpg",
"name": "",
"alt": "",
"position": 3
}
],
"attributes": [
{
"id": 6,
"name": "Color",
"position": 0,
"visible": false,
"variation": true,
"options": [
"Black",
"Green"
]
},
{
"id": 0,
"name": "Size",
"position": 0,
"visible": true,
"variation": true,
"options": [
"S",
"M"
]
}
],
"default_attributes": [],
"variations": [],
"grouped_products": [],
"menu_order": 0,
"meta_data": [],
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/products/799"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/products"
}
]
}
},
{
"id": 794,
"name": "Premium Quality",
"slug": "premium-quality-19",
"permalink": "https://example.com/product/premium-quality-19/",
"date_created": "2017-03-23T17:01:14",
"date_created_gmt": "2017-03-23T20:01:14",
"date_modified": "2017-03-23T17:01:14",
"date_modified_gmt": "2017-03-23T20:01:14",
"type": "simple",
"status": "publish",
"featured": false,
"catalog_visibility": "visible",
"description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>\n",
"short_description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>\n",
"sku": "",
"price": "21.99",
"regular_price": "21.99",
"sale_price": "",
"date_on_sale_from": null,
"date_on_sale_from_gmt": null,
"date_on_sale_to": null,
"date_on_sale_to_gmt": null,
"price_html": "<span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">&#36;</span>21.99</span>",
"on_sale": false,
"purchasable": true,
"total_sales": 0,
"virtual": false,
"downloadable": false,
"downloads": [],
"download_limit": -1,
"download_expiry": -1,
"external_url": "",
"button_text": "",
"tax_status": "taxable",
"tax_class": "",
"manage_stock": false,
"stock_quantity": null,
"in_stock": true,
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"sold_individually": false,
"weight": "",
"dimensions": {
"length": "",
"width": "",
"height": ""
},
"shipping_required": true,
"shipping_taxable": true,
"shipping_class": "",
"shipping_class_id": 0,
"reviews_allowed": true,
"average_rating": "0.00",
"rating_count": 0,
"related_ids": [
463,
47,
31,
387,
458
],
"upsell_ids": [],
"cross_sell_ids": [],
"parent_id": 0,
"purchase_note": "",
"categories": [
{
"id": 9,
"name": "Clothing",
"slug": "clothing"
},
{
"id": 14,
"name": "T-shirts",
"slug": "t-shirts"
}
],
"tags": [],
"images": [
{
"id": 792,
"date_created": "2017-03-23T14:01:13",
"date_created_gmt": "2017-03-23T20:01:13",
"date_modified": "2017-03-23T14:01:13",
"date_modified_gmt": "2017-03-23T20:01:13",
"src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg",
"name": "",
"alt": "",
"position": 0
},
{
"id": 793,
"date_created": "2017-03-23T14:01:14",
"date_created_gmt": "2017-03-23T20:01:14",
"date_modified": "2017-03-23T14:01:14",
"date_modified_gmt": "2017-03-23T20:01:14",
"src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg",
"name": "",
"alt": "",
"position": 1
}
],
"attributes": [],
"default_attributes": [
{
"id": 6,
"name": "Color",
"option": "black"
},
{
"id": 0,
"name": "Size",
"option": "S"
}
],
"variations": [],
"grouped_products": [],
"menu_order": 0,
"meta_data": [],
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/products/794"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/products"
}
]
}
}
]

get
Get Product Categories

https://your-hosting.com
/wp-json/wc/v2/categories
This help to list all the categories
Request
Response
Query Parameters
per_page
optional
number
Maximum number of items to be returned in result set. Default is 10.
page
optional
number
Current page of the collection, default is 1
200: OK
[
{
"id": 15,
"name": "Albums",
"slug": "albums",
"parent": 11,
"description": "",
"display": "default",
"image": [],
"menu_order": 0,
"count": 4,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories/15"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories"
}
],
"up": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories/11"
}
]
}
},
{
"id": 9,
"name": "Clothing",
"slug": "clothing",
"parent": 0,
"description": "",
"display": "default",
"image": {
"id": 730,
"date_created": "2017-03-23T00:01:07",
"date_created_gmt": "2017-03-23T03:01:07",
"date_modified": "2017-03-23T00:01:07",
"date_modified_gmt": "2017-03-23T03:01:07",
"src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg",
"title": "",
"alt": ""
},
"menu_order": 0,
"count": 36,
"_links": {
"self": [
{
"href": "https://example/wp-json/wc/v2/products/categories/9"
}
],
"collection": [
{
"href": "https://example/wp-json/wc/v2/products/categories"
}
]
}
},
{
"id": 10,
"name": "Hoodies",
"slug": "hoodies",
"parent": 9,
"description": "",
"display": "default",
"image": [],
"menu_order": 0,
"count": 6,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories/10"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories"
}
],
"up": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories/9"
}
]
}
},
{
"id": 11,
"name": "Music",
"slug": "music",
"parent": 0,
"description": "",
"display": "default",
"image": [],
"menu_order": 0,
"count": 7,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories/11"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories"
}
]
}
},
{
"id": 12,
"name": "Posters",
"slug": "posters",
"parent": 0,
"description": "",
"display": "default",
"image": [],
"menu_order": 0,
"count": 5,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories/12"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories"
}
]
}
},
{
"id": 13,
"name": "Singles",
"slug": "singles",
"parent": 11,
"description": "",
"display": "default",
"image": [],
"menu_order": 0,
"count": 3,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories/13"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories"
}
],
"up": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories/11"
}
]
}
},
{
"id": 14,
"name": "T-shirts",
"slug": "t-shirts",
"parent": 9,
"description": "",
"display": "default",
"image": [],
"menu_order": 0,
"count": 6,
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories/14"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories"
}
],
"up": [
{
"href": "https://example.com/wp-json/wc/v2/products/categories/9"
}
]
}
}
]

get
List all payment gateways

https://your-hosting.com
/wp-json/wc/v2/payments_gateways
This API helps you to view all the payment gateways
Request
Response
Query Parameters
per_page
optional
number
Maximum number of items to be returned in result set. Default is 10.
page
optional
number
Current page of the collection, default is 1
200: OK
[
{
"id": "bacs",
"title": "Direct bank transfer",
"description": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.",
"order": 0,
"enabled": true,
"method_title": "BACS",
"method_description": "Allows payments by BACS, more commonly known as direct bank/wire transfer.",
"settings": {
"title": {
"id": "title",
"label": "Title",
"description": "This controls the title which the user sees during checkout.",
"type": "text",
"value": "Direct bank transfer",
"default": "Direct bank transfer",
"tip": "This controls the title which the user sees during checkout.",
"placeholder": ""
},
"instructions": {
"id": "instructions",
"label": "Instructions",
"description": "Instructions that will be added to the thank you page and emails.",
"type": "textarea",
"value": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.",
"default": "",
"tip": "Instructions that will be added to the thank you page and emails.",
"placeholder": ""
}
},
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/payment_gateways/bacs"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/payment_gateways"
}
]
}
},
{
"id": "cheque",
"title": "Check payments",
"description": "Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.",
"order": 1,
"enabled": false,
"method_title": "Check payments",
"method_description": "Allows check payments. Why would you take checks in this day and age? Well you probably wouldn't but it does allow you to make test purchases for testing order emails and the 'success' pages etc.",
"settings": {
"title": {
"id": "title",
"label": "Title",
"description": "This controls the title which the user sees during checkout.",
"type": "text",
"value": "Check payments",
"default": "Check payments",
"tip": "This controls the title which the user sees during checkout.",
"placeholder": ""
},
"instructions": {
"id": "instructions",
"label": "Instructions",
"description": "Instructions that will be added to the thank you page and emails.",
"type": "textarea",
"value": "",
"default": "",
"tip": "Instructions that will be added to the thank you page and emails.",
"placeholder": ""
}
},
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/payment_gateways/cheque"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/payment_gateways"
}
]
}
},
{
"id": "cod",
"title": "Cash on delivery",
"description": "Pay with cash upon delivery.",
"order": 2,
"enabled": false,
"method_title": "Cash on delivery",
"method_description": "Have your customers pay with cash (or by other means) upon delivery.",
"settings": {
"title": {
"id": "title",
"label": "Title",
"description": "Payment method description that the customer will see on your checkout.",
"type": "text",
"value": "Cash on delivery",
"default": "Cash on delivery",
"tip": "Payment method description that the customer will see on your checkout.",
"placeholder": ""
},
"instructions": {
"id": "instructions",
"label": "Instructions",
"description": "Instructions that will be added to the thank you page.",
"type": "textarea",
"value": "",
"default": "Pay with cash upon delivery.",
"tip": "Instructions that will be added to the thank you page.",
"placeholder": ""
},
"enable_for_methods": {
"id": "enable_for_methods",
"label": "Enable for shipping methods",
"description": "If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.",
"type": "multiselect",
"value": "",
"default": "",
"tip": "If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.",
"placeholder": "",
"options": {
"flat_rate": "Flat rate",
"free_shipping": "Free shipping",
"local_pickup": "Local pickup"
}
},
"enable_for_virtual": {
"id": "enable_for_virtual",
"label": "Accept COD if the order is virtual",
"description": "",
"type": "checkbox",
"value": "yes",
"default": "yes",
"tip": "",
"placeholder": ""
}
},
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/payment_gateways/cod"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/payment_gateways"
}
]
}
},
{
"id": "paypal",
"title": "PayPal",
"description": "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.",
"order": 3,
"enabled": true,
"method_title": "PayPal",
"method_description": "PayPal Standard sends customers to PayPal to enter their payment information. PayPal IPN requires fsockopen/cURL support to update order statuses after payment. Check the <a href=\"https://example.com/wp-admin/admin.php?page=wc-status\">system status</a> page for more details.",
"settings": {
"title": {
"id": "title",
"label": "Title",
"description": "This controls the title which the user sees during checkout.",
"type": "text",
"value": "PayPal",
"default": "PayPal",
"tip": "This controls the title which the user sees during checkout.",
"placeholder": ""
},
"email": {
"id": "email",
"label": "PayPal email",
"description": "Please enter your PayPal email address; this is needed in order to take payment.",
"type": "email",
"value": "me@example.com",
"default": "me@example.com",
"tip": "Please enter your PayPal email address; this is needed in order to take payment.",
"placeholder": "you@youremail.com"
},
"testmode": {
"id": "testmode",
"label": "Enable PayPal sandbox",
"description": "PayPal sandbox can be used to test payments. Sign up for a <a href=\"https://developer.paypal.com/\">developer account</a>.",
"type": "checkbox",
"value": "yes",
"default": "no",
"tip": "PayPal sandbox can be used to test payments. Sign up for a <a href=\"https://developer.paypal.com/\">developer account</a>.",
"placeholder": ""
},
"debug": {
"id": "debug",
"label": "Enable logging",
"description": "Log PayPal events, such as IPN requests, inside <code>/var/www/woocommerce/wp-content/uploads/wc-logs/paypal-de01f7c6894774e7ac8e4207bb8bac2f.log</code>",
"type": "checkbox",
"value": "yes",
"default": "no",
"tip": "Log PayPal events, such as IPN requests, inside <code>/var/www/woocommerce/wp-content/uploads/wc-logs/paypal-de01f7c6894774e7ac8e4207bb8bac2f.log</code>",
"placeholder": ""
},
"receiver_email": {
"id": "receiver_email",
"label": "Receiver email",
"description": "If your main PayPal email differs from the PayPal email entered above, input your main receiver email for your PayPal account here. This is used to validate IPN requests.",
"type": "email",
"value": "me@example.com",
"default": "",
"tip": "If your main PayPal email differs from the PayPal email entered above, input your main receiver email for your PayPal account here. This is used to validate IPN requests.",
"placeholder": "you@youremail.com"
},
"identity_token": {
"id": "identity_token",
"label": "PayPal identity token",
"description": "Optionally enable \"Payment Data Transfer\" (Profile > Profile and Settings > My Selling Tools > Website Preferences) and then copy your identity token here. This will allow payments to be verified without the need for PayPal IPN.",
"type": "text",
"value": "",
"default": "",
"tip": "Optionally enable \"Payment Data Transfer\" (Profile > Profile and Settings > My Selling Tools > Website Preferences) and then copy your identity token here. This will allow payments to be verified without the need for PayPal IPN.",
"placeholder": ""
},
"invoice_prefix": {
"id": "invoice_prefix",
"label": "Invoice prefix",
"description": "Please enter a prefix for your invoice numbers. If you use your PayPal account for multiple stores ensure this prefix is unique as PayPal will not allow orders with the same invoice number.",
"type": "text",
"value": "WC-",
"default": "WC-",
"tip": "Please enter a prefix for your invoice numbers. If you use your PayPal account for multiple stores ensure this prefix is unique as PayPal will not allow orders with the same invoice number.",
"placeholder": ""
},
"send_shipping": {
"id": "send_shipping",
"label": "Send shipping details to PayPal instead of billing.",
"description": "PayPal allows us to send one address. If you are using PayPal for shipping labels you may prefer to send the shipping address rather than billing.",
"type": "checkbox",
"value": "no",
"default": "no",
"tip": "PayPal allows us to send one address. If you are using PayPal for shipping labels you may prefer to send the shipping address rather than billing.",
"placeholder": ""
},
"address_override": {
"id": "address_override",
"label": "Enable \"address_override\" to prevent address information from being changed.",
"description": "PayPal verifies addresses therefore this setting can cause errors (we recommend keeping it disabled).",
"type": "checkbox",
"value": "no",
"default": "no",
"tip": "PayPal verifies addresses therefore this setting can cause errors (we recommend keeping it disabled).",
"placeholder": ""
},
"paymentaction": {
"id": "paymentaction",
"label": "Payment action",
"description": "Choose whether you wish to capture funds immediately or authorize payment only.",
"type": "select",
"value": "sale",
"default": "sale",
"tip": "Choose whether you wish to capture funds immediately or authorize payment only.",
"placeholder": "",
"options": {
"sale": "Capture",
"authorization": "Authorize"
}
},
"page_style": {
"id": "page_style",
"label": "Page style",
"description": "Optionally enter the name of the page style you wish to use. These are defined within your PayPal account. This affects classic PayPal checkout screens.",
"type": "text",
"value": "",
"default": "",
"tip": "Optionally enter the name of the page style you wish to use. These are defined within your PayPal account. This affects classic PayPal checkout screens.",
"placeholder": "Optional"
},
"image_url": {
"id": "image_url",
"label": "Image url",
"description": "Optionally enter the URL to a 150x50px image displayed as your logo in the upper left corner of the PayPal checkout pages.",
"type": "text",
"value": "",
"default": "",
"tip": "Optionally enter the URL to a 150x50px image displayed as your logo in the upper left corner of the PayPal checkout pages.",
"placeholder": "Optional"
},
"api_username": {
"id": "api_username",
"label": "API username",
"description": "Get your API credentials from PayPal.",
"type": "text",
"value": "",
"default": "",
"tip": "Get your API credentials from PayPal.",
"placeholder": "Optional"
},
"api_password": {
"id": "api_password",
"label": "API password",
"description": "Get your API credentials from PayPal.",
"type": "password",
"value": "",
"default": "",
"tip": "Get your API credentials from PayPal.",
"placeholder": "Optional"
},
"api_signature": {
"id": "api_signature",
"label": "API signature",
"description": "Get your API credentials from PayPal.",
"type": "text",
"value": "",
"default": "",
"tip": "Get your API credentials from PayPal.",
"placeholder": "Optional"
}
},
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v2/payment_gateways/paypal"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v2/payment_gateways"
}
]
}
}
]