magento / devdocs

[Deprecated] Magento Developer Documentation
Open Software License 3.0
673 stars 1.76k forks source link

Magento2 API Custom Cart with Braintree #615

Closed kgvconsulting closed 8 years ago

kgvconsulting commented 8 years ago

We are trying to integrate the magento2 with a custom cart for an app we are making, however we are stuck in trying to place the order (we are creating the cart, with items, quantity, and shipping method) From the magento2 documentation this should be done with a POST to /payment-information but the rest is unclear in terms of the contents of the request. From the braintree documentation in order to use the drop-in UI to tokenize the card information we need a clientToken which our server should generate, however we cannot find the endpoint which returns that token for us.

Can someone point us to a code snippet or example of the checkout process using braintree or give a high level overview of how to go about getting the necessary information to place an order for /payment-information

Thank you

Edit: Just for reference I see here http://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_payment.html it is described that the clientToken (along with other info) is added to the global variable window.checkoutConfig.braintree. So I am assuming that there is no REST call exposed to get this information?

tanberry commented 8 years ago

Hi @kgvconsulting, thanks for your questions. We are consulting with a core developer and will get back to you!

dkvashninbay commented 8 years ago

Hi @kgvconsulting for this purpose you need to define payment config provider for Checkout. Here is an example of such class: https://github.com/magento/magento2/blob/develop/app/code/Magento/Braintree/Model/Ui/ConfigProvider.php#L73

And it should be registered in configuration, like this one: https://github.com/magento/magento2/blob/develop/app/code/Magento/Braintree/etc/frontend/di.xml#L12

And you should also define Client side components (JS) in layouts: https://github.com/magento/magento2/blob/develop/app/code/Magento/Braintree/view/frontend/layout/checkout_index_index.xml

Also you may reuse Braintree UI component to get clientToken in your module https://github.com/magento/magento2/blob/develop/app/code/Magento/Braintree/view/frontend/web/js/view/payment/adapter.js#L66

Hope that helped :)