48

Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple
Page 2: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Magento 2

Integration

Technologies

Page 3: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Alan KentMagento Chief Architect

Page 4: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Jeff has set up his own online store

It is doing well and sales are growing

Meet Jeff

But how does he grow his business to the next level?

Page 5: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Potential Integration PointsPIM

BUY BUY BUY

Buy Buttons

Native Mobile Apps

SaaS Connectors

Order Management

Internet of Things

Page 6: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Business Logic

(extension developers)

Integration Configuration

(system integrators)

Want separation of Business Logic from

Integration Configuration

Page 7: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Jeff needs to reduce the cost of integrations

Page 8: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Magento 2.X is Solving the Integration Challenge

Authentication made simple

Easy Custom APIs

More out-of-the-box APIs

REST

SOAP

AMQP

Service Contracts

Page 9: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Multiple Authentication Needs

JavaScript in web browser already has authenticated users

Enterprise systems must authenticate with humans present

Mobile apps collect credentials from users

Session Cookie

Username Password

Token OAuth 1.0a Long Life

Auth Token

Page 10: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Mobile App – Authentication

Authenticate using username and password

$ curl -X POST "https://127.0.0.1/rest/V1/integration/admin/token" \

-H "Content-Type:application/json" \

-d '{"username":"admin", "password":"XXXXX"}'

"w2rq3acoc6bbtxdbbhmybmxq1nm60j24"

Retrieve list of loaded modules

$ curl https://127.0.0.1/rest/V1/modules \

-H "Authorization: Bearer w2rq3acoc6bbtxdbbhmybmxq1nm60j24"

["Magento_Store","Magento_AdvancedPricingImportExport",...,"Magento_

Wishlist"]

1

2

Page 11: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

M2: More Standard APIs out of the Box

Catalog

Inventory

Cart

Order

Customer

SearchTax

CMS

Page 12: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

• Adding modules can change

the available REST and SOAP

services

• Look for webapi.xml files –

{Vendor}/{ModuleName}

/etc/webapi.xml

• Swagger based documentation

available online

• Swagger on your site –

localized based on which

modules are loaded.

http://devdocs.magento.com/swagger

Discovering API Coverage

http://127.0.0.1/index.php/rest/default/schema

Page 13: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

PIM Calling Magento 2

curl –H "Content-Type: application/json“ –H "Authentication: XXX“ --data-raw @file.json

HTTP POST /V1/products

onPostSave()

JSON

{

"id": 0,

"sku": “SPD-3393",

"name": “Super fast shoes",

"storeId": 0,

"attributeSetId": 0,

"price": 20.22,

"extensionAttributes": {

...

webapi.xml

<routes ...>

<!-- Product Service -->

<route url="/V1/products" method="POST">

<service class="Magento\Catalog\Api\ProductRepositoryInterface“

method="save"/>

<resources>

<resource ref="Magento_Catalog::products" />

</resources>

</route>

...

webapi.xml

Create new product

Page 14: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Simpler REST and SOAP Services

• Service contracts are

– PHP interfaces

– Designed to be called from presentation layer and other modules

– Also bound to web services

• Arguments are

– Restricted to types easy to serialize as JSON

namespace Magento\Catalog\Api;

interface ProductRepositoryInterface

{

/**

* Create product

*

* @param \Magento\Catalog\Api\Data\ProductInterface $product

* @param bool $saveOptions

* @return \Magento\Catalog\Api\Data\ProductInterface

* @throws \Magento\Framework\Exception\InputException

* @throws \Magento\Framework\Exception\StateException

* @throws \Magento\Framework\Exception\CouldNotSaveException

*/

public function save(\Magento\Catalog\Api\Data\ProductInterface $product,

$saveOptions = false);

WSDL: http://127.0.0.1/soap?wsdl&services=customerCustomerAccountServiceV1,catalogProductV2

Page 15: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Retrieving Product Information

http://cyrillschumacher.com/2015/01/02/magento2---search-parameters-for-the-rest-api/

OR

AND

CONSTRAINTS

PAGINATION

SORTING

Fetch: curl http://127.0.0.1/rest/V1/products/12345

Search:curl -X PUT -i-H 'Content-type: application/json‘-d '{"search_criteria":{…}}' http://127.0.0.1/rest/V1/search

Page 16: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Cart

Cart manipulation (quoteCartManagementV1)• POST /V1/carts – creates new empty cart• PUT /V1/carts/{cartid} – associate cart with a customer

Get quote for cart (checkoutGuestTotalsInformationManagementV1)• POST /V1/carts/{cartId}/totals-information – returns how

much the cart will cost (to show user before checkout)

Specify payment information and place order (checkoutPaymentInformationManagementV1)

• POST /V1/carts/mine/payment-information

Page 17: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Custom APIs – Why?

Want an API optimized for mobile

Magento has not defined service contracts yet

IOT devices mapping IDs to customers and order

preferences

Page 18: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Custom APIs – How?

1.Write service contract (PHP interfaces)

2. Implement the interfaces with business logic

3.Bind REST and/or SOAP the API via webapi.xml

4.Review security settings, including acl.xml

No JSON/XML serialization

code

No authentication

code

Automatic separation of config from

logic

Page 19: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

AMQP

• Can receive an AMQP message and bind onto service

contract

– No reply-to support yet

• There is an API allowing publishing of messages

– Hand craft messages

– Similar to M2 HTTP client library<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message

<publisher name="default" connection="amqp" exchange="magento”/>

<topic name="customer.created" schema="Magento\Customer\Api\AccountManagementInterface::createAccount" publisher="default" />

<bind queue="customer_created" exchange="magento" topic="customer.created" />

<consumer name="customerCreated" queue="customer_created" class="Magento\Customer\Api\AccountManagementInterface" method="createAccount

</config>

$this->publisher->publish(

'customer.created',

['customer' => $customer]

);

Page 20: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Future Exploration

• Synchronous MQ inbound calls

• Outbound REST call via service contract

• Outbound SOAP via service contract

• Webhook support

• Outbound synchronous (RPC call) and asynchronous

(publish) over MQ via service contract

Page 21: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Jeff’s Orders are Booming

Life is Good!

Page 22: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Twitter: @akent99

Blog: http://alankent.me

Forum: https://community.magento.com/ (Just Ask Alan)

THANK YOU!

Page 23: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Max YekaterynenkoHead of Magento 2 Development

maksek_ua

[email protected]

Page 24: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Quality &

Magento 2

Page 25: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Magento 2 Platform Goals

M2

Modern Tech Stack

Improved Performance &

Scalability

StreamlineCustomization

Simplify ExternalIntegrations

Easier installation & upgrades

High code quality

& testing

Page 26: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Code Quality & Testing

Merchant Extension developer

System Integrator Magento Commerce

Page 27: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

“For the first time, testing was fun”

Page 28: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Acceptance

Functional

Performance

Static

Integration & API

Unit

Test Types

Page 29: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Unit Test

• Isolated

• Fast

• Distributed with Module

• PhpUnit https://phpunit.de/

Page 30: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Integration and API

Page 31: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Integration and API

• “Black-box”

• Integration Framework >dev/tests/integration/framework

• Not fast

• PhpUnit

Page 32: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Static

• PHPMD

• PHPCS

• PHPCPD

• Magento-specific integrity tests

• >dev/tests/static/

Page 33: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Performance

• JMeter

• End-To-End Scenarios

Page 34: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Magento Testing Framework

Page 35: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Magento Testing Framework

Page 36: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Magento Testing Framework

• End user experience testing

• >dev/tests/functional/

• Selenium Webdriver (+Grid)

• Slow, very slow

Page 37: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Magento 2 Quality

Unit Tests Integration Web API Functional

16000+ CE4000+ EE

>35%

3200+ CE

400+ EE

640+ CE

50+ EE

300+ scenarios

1000 documented

Page 38: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Magento 2 Quality Stack

Page 39: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

GitHub

Page 40: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Code Review

Page 41: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Bamboo

Page 42: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Bamboo

Page 43: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Acceptance Cycle

Page 44: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Travis-CI

Page 45: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Code Quality & Testing

Merchant Extension developer

System Integrator Magento Commerce

Page 46: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Thank you!

Page 47: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Q&A

Page 48: Magento 2 Integration 2...Magento 2.X is Solving the Integration Challenge Authentication made simple Easy Custom APIs More out-of-the-box APIs REST SOAP AMQP Service Contracts Multiple

Max YekaterynenkoHead of Magento 2 Development

maksek_ua

[email protected]