candies for everybody - meet magento italia 2015
TRANSCRIPT
Candies for everybody: hacking from 9 to 6
Alberto López Braintree_Dev.
<Advocate/>
https://flic.kr/p/6kFQBc
4.9 Billion Connected "Things" by 2015
http://www.gartner.com/newsroom/id/2905717
Gartner Symposium/ITxpo 2014, November 9-13 in Barcelona, Spain
@AlbertusLM@Braintree_Dev
why Braintree v.zero SDK?
v.zeroOFF
ON
ON
ON
ON
OFF
ON
ON
ON
ON
FUTURE Payment Method
C&D Cards
@AlbertusLM@Braintree_Dev
why Magento?
> open source
> created for eCommerce
> fully scalable
> high performance
> great look&feel
@AlbertusLM@Braintree_Dev
why spark core?
> open source
> wifi connected
> tiny size
> code on private cloud
> multi-language
@AlbertusLM@Braintree_Dev
Ouch!
> Old Braintree module
> v.zero not available yet (official plugin in development)
@AlbertusLM@Braintree_Dev
Frontend: <templateFile>.phtml
[…] <form id="Braintree_vzero"> </form>
<script src=“https://js.braintreegateway.com/v2/braintree.js"></script>
<script type="text/javascript"> braintree.setup(
"<?php echo $clientToken;?>", 'dropin', {
container: ‘Braintree_vzero’, }
}); </script> […]
@AlbertusLM@Braintree_Dev
Frontend: <templateFile>.phtml
[…] <form id="Braintree_vzero"> </form>
<script src=“https://js.braintreegateway.com/v2/braintree.js"></script>
<script type="text/javascript"> braintree.setup(
"<?php echo $clientToken;?>", 'dropin', {
container: ‘Braintree_vzero’, }
}); </script> […]
@AlbertusLM@Braintree_Dev
Frontend: <templateFile>.phtml
[…] <form id="Braintree_vzero"> </form>
<script src=“https://js.braintreegateway.com/v2/braintree.js"></script>
<script type="text/javascript"> braintree.setup(
"<?php echo $clientToken;?>", 'dropin', {
container: ‘Braintree_vzero’, }
}); </script> […]
@AlbertusLM@Braintree_Dev
Frontend: <templateFile>.phtml
[…] <form id="Braintree_vzero"> </form>
<script src=“https://js.braintreegateway.com/v2/braintree.js"></script>
<script type="text/javascript"> braintree.setup(
"<?php echo $clientToken;?>", 'dropin', {
container: ‘Braintree_vzero’, }
}); </script> […]
@AlbertusLM@Braintree_Dev
Backend: <ModelFile>.php
[…]
Braintree_Configuration::merchantId(‘YOUR_MERCHANT_ID’);
Braintree_Configuration::publicKey(‘YOUR_PUBLIC_KEY');
Braintree_Configuration::privateKey(‘YOUR_PRIVATE_KEY’);
[...]
Security: Setting API Credentials
@AlbertusLM@Braintree_Dev
Backend: <ModelFile>.php
[...] class Braintree_Vzero_Block_Form extends Mage_Payment_Block_Form { protected function _construct() { parent::_construct(); $this->setTemplate('vzero/form.phtml'); }
[…]
public function getClientToken() { $clientToken = Braintree_ClientToken::generate(array()); $this->setData('clientToken', $clientToken); return $clientToken; } } [...]
Asking for ClientToken (creating UI payment form)
@AlbertusLM@Braintree_Dev
Backend: <ModelFile>.php
[...] class Braintree_Vzero_Block_Form extends Mage_Payment_Block_Form { protected function _construct() { parent::_construct(); $this->setTemplate('vzero/form.phtml'); }
[…]
public function getClientToken() { $clientToken = Braintree_ClientToken::generate(array()); $this->setData('clientToken', $clientToken); return $clientToken; } } [...]
Asking for ClientToken (creating UI payment form)
@AlbertusLM@Braintree_Dev
Backend: <ModelFile>.php
[...] $result = Braintree_Transaction::sale(array(
'amount' => $grandTotal, 'paymentMethodNonce' => $paymentNonce, 'shipping' => array(
'firstName' => $firstName, 'lastName' => $lastName, 'streetAddress' => $streetAddress, 'locality' => $locality, 'region' => $stateOrProvince, 'countryName' => $countryName
), 'customFields' => array(
'cart' => $cart ) )); $transactionID = $result->transaction->id; [...]
NOTE Getting previously these parameters from the checkout: • 'cart'-> array with the cart details • 'grandTotal'-> total amount • 'paymentNonce'->payment_method_nonce
Finishing the transaction
@AlbertusLM@Braintree_Dev
Backend: <ModelFile>.php
[...] $result = Braintree_Transaction::sale(array(
'amount' => $grandTotal, 'paymentMethodNonce' => $paymentNonce,'shipping' => array(
'firstName' => $firstName, 'lastName' => $lastName, 'streetAddress' => $streetAddress, 'locality' => $locality, 'region' => $stateOrProvince, 'countryName' => $countryName
), 'customFields' => array(
'cart' => $cart ) )); $transactionID = $result->transaction->id; [...]
NOTE v.zero form doesn’t send to backend personal information. You only have a nonce to finish the transaction.
Finishing the transaction
@AlbertusLM@Braintree_Dev
Backend: <ModelFile>.php
[...] $result = Braintree_Transaction::sale(array(
'amount' => $grandTotal, 'paymentMethodNonce' => $paymentNonce, 'shipping' => array(
'firstName' => $firstName, 'lastName' => $lastName, 'streetAddress' => $streetAddress, 'locality' => $locality, 'region' => $stateOrProvince, 'countryName' => $countryName
), 'customFields' => array(
'cart' => $cart ) )); $transactionID = $result->transaction->id; [...]
Finishing the transaction
@AlbertusLM@Braintree_Dev
Backend: <ModelFile>.php
[...]
$accessToken = ‘your_access_token';
$core = SparkCore::make($accessToken); $core->setDeviceId('your_device_id');
$core->setFunction('movemotor'); $core->setParams(array(‘transactionID'));
$result = $core->run(); echo $result->return_value;
[...]
Sending info to Candy Machine
NOTE Library: garethtdavies/SparkPHP
Enjoy! Tr.ID: dfr43
@AlbertusLM@Braintree_Dev
Spark Core: <filename>.ino
void setup() { […] //setup TFT tft.begin();
//setup SD SD.begin(SD_CS);
//setup DC Motor pinMode(MOTOR, OUTPUT);
//Register our Spark function here Spark.function("candy", moveMotorCandy); […] }
Setting up the device
NOTE TFT/SD: pkourany/ILI9341_SPI_LCD
Enjoy! Tr.ID: dfr43
@AlbertusLM@Braintree_Dev
Spark Core: <filename>.ino
[…] int moveMotorCandy(String command) { //Adjustment to present correctly the text on the screen String textToPrint = " Enjoy! \n Tr.ID: "+ command;
//Printing the MotorMovement screen bmpDraw("motor.bmp", 0, 0); showTextInScreen (textToPrint,10,160); delay(1000);
digitalWrite(MOTOR, 1); // Turn ON the motor delay(milisecsMovingMotor); digitalWrite(MOTOR, 0); // Turn OFF the motor
delay(3000); setScreenToStandBy(); } […] }
Expending the candies
NOTE TFT/SD: pkourany/ILI9341_SPI_LCD
Enjoy! Tr.ID: dfr43
@AlbertusLM@Braintree_Dev
Braintree: braintreepayments.com
v.zero: braintreepayments.com/v.zero
Dev Braintree Portal: developers.braintreepayments.com
Demo in Hackster.io: hackster.io/AlbertoLopez/candy-machine-with-v-zero-sdk
@AlbertusLM@Braintree_Dev
ask him
Source photo