dsyo9700 2019-01-04 08:25
浏览 51
已采纳

Symfony 4 - 设置Braintree Payments集成

I am trying to set up Braintree integration in my Symfony 4 PHP app.

I have used composer to require and install the latest version of Braintree SDK, and have added testing credentials to env file.

Set Up Client

https://developers.braintreepayments.com/start/hello-client/javascript/v3

I then added the client code to my twig template for Drop-in UI.

<div id="dropin-container"></div>
<button id="submit-button">Request payment method</button>
<script>
 var button = document.querySelector('#submit-button');

 braintree.dropin.create({
  authorization: 'CLIENT_TOKEN_FROM_SERVER',
  container: '#dropin-container'
 }, function (createErr, instance) {
  button.addEventListener('click', function () {
   instance.requestPaymentMethod(function (err, payload) {
     // Submit payload.nonce to your server
   });
  });
 });
</script>

And included this script in the js block

<script src="https://js.braintreegateway.com/web/dropin/1.14.1/js/dropin.min.js"></script>

Set Up Server

https://developers.braintreepayments.com/start/hello-server/php

Next step is to generate a client token

$clientToken = $gateway->clientToken()->generate([
    "customerId" => $aCustomerId
]);

and then send token to client etc.

Question

My question is where do I put the server side code in my Symfony 4 app?

Do you create a Braintree.php service in src/Services and put all the Braintree PHP code in there or in the controller, or some in both?

  • 写回答

1条回答 默认 最新

  • dornc9470 2019-01-04 09:21
    关注

    Best practice is to keep Controllers as thin as possible. Controller method should:

    • accept the request
    • call the appropriate service
    • handle response

    This is all a controller should be responsible of. In your case, the appropriate service would be your BraintreeService, a class responsible for whatever you need to do with Braintree SDK or anything related to Braintree.

    Symfony follows the philosophy of "thin controllers and fat models". This means that controllers should hold just the thin layer of glue-code needed to coordinate the different parts of the application.

    https://symfony.com/doc/current/best_practices/controllers.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用