黄色视频

    1. <form id=QUkGStDXb><nobr id=QUkGStDXb></nobr></form>
      <address id=QUkGStDXb><nobr id=QUkGStDXb><nobr id=QUkGStDXb></nobr></nobr></address>

      Show Navigation

      payment

      Grails payment plugin

      Owner: vahidhedayati | 1.0.1 | Jun 22, 2021 | Package | Issues | Source | License: Apache-2.0

      0
      
      dependencies {
          compile 'io.github.vahidhedayati:payment:1.0.1'
      }
      
                  

      Grails Payment plugin

      Author: Vahid Hedayati

      Date: 18th June 2021

      Grails Payment Plugin written in Grails 4

      Installation for a grails 4 application

      Add dependency to build.gradle:

      
      dependencies {
      
       
        compile "io.github.vahidhedayati:payment:1.0.1"
      
        //You will only need this if you are looking to use square payment
        compile 'org.jetbrains.kotlin:kotlin-stdlib:1.3.70'
      
      }
      

      Supports 3 payment systems that you can simply add to your site:

      Paypal

      Stripe

      Square

      It provides a web interface so you can update database and underlying configuration listener with following details:

      Enable / Disable any / all providers as you like

      Change from SANDBOX to LIVE on any or all give providers

      Change sandbox / live secret / public keys for any / all providers.

      All underlying providers use the listener configuration values and as any change is made the provides will instantly pick up those effects.

      Getting plugin to work on a sample site:

      Copy SampleApplication.groovy from conf folder in plugin to your app as /grails-app/conf/application.groovy Update according to your provider keys / configuration:

      
      
      payment {
          currencyCode = org.grails.plugin.payment.enums.CurrencyTypes.GBP
          countryCode = org.grails.plugin.payment.enums.CountryCode.GB
          hostName = "http://localhost:8080"
          square {
              applicationId = 'LIVE_APP_ID'
              accessToken = 'LIVE_ACCESS_TOKEN'
              location='LOC1' //get this from location tab in square api dev console
              applicationSecret = 'LIVE APP SECRET'  //oauth
              enabled=true
              mode='sandbox'  // choose sandbox or live in web interface
              sandbox {
                  applicationId = 'sandbox-sq0111-S1sssd3232ssA'
                  accessToken = 'EAAAExxdeee22wwwwwww2aaaaakkty'
                  applicationSecret = 'sandbox-sqsww-ss222222sssssssssssT-tQsaq2o'  //oauth
                  location='Lxxsa34aa3'
              }
          }
      
      
          paypal{
              enabled=true
              mode='sandbox'  // choose sandbox or live in web interface
              email="[email protected]"
              clientId = 'AZsdfdsfsrewrwerwesddsfdsfsdfdsfsdfsgswresdfdsfgfdsfsdfd-1'
              clientSecret = 'EEsdfdsfsdfsfsdfdsfsdfsdfdsfdsfsdfdsfdsfdsfddsdsdsdsffds_oi'
              endpoint = "https://api.paypal.com"
              sandbox{
                  email='[email protected]'
                  clientId = 'AZsdfdsfdsfdsfdsfdsdf-sdfsdfdsfdsfdsfsdfsdfdsfsdfsdfdsfddsf-1'
                  clientSecret ='EEsdfdsfdsfdsfsdfdsfdsfdsfdsdfsdsdfsdsdfddffddsfdf_oi'
                  endpoint = "https://api.sandbox.paypal.com"
              }
          }
          stripe {
              ecretKey = 'YOUR_LIVE_SECRET_KEY'
              publishableKey = 'YOUR_LIVE_PUBLISHABLE_KEY'
              enabled=true
              mode='sandbox'  // choose sandbox or live in web interface
              test {
                  secretKey='sk_test_51dsfdsfdsfdsfdsfdsfsfsdfsdfdfdfdsdfDQ'
                  publishableKey= 'pk_test_51sdfdsfdsfdsfdsfdsdsfdfsdsdsdssdsfdsddsdfddfsdsd9'
              }
          }
      
      }
      

      Then update init/{package}/BootStrap.groovy This simply loads in application.groovy's configuration into PaymentConfig domain class and copies all configuration values to a listener which updates all providers immediately

      class BootStrap {
      
          def paymentService
          def init = { servletContext ->
      
              paymentService.addPaymentConfig()
          }
          def destroy = {
          }
      }
      

      Start up your test site, there will now be an additional 2 controllers available:

      http://localhost:8080/payment you will be working with:

      http://localhost:8080/payment/checkout

      http://localhost:8080/paymentConfig

      Full walkthrough video

      You-Tube Video showing plugin in use

      You-Tube Video Part 2 easier usage of plugin explained

      How to use plugin locally

      By installing the plugin you get the working steps to make payments work and all of the code to execute run it. If what you see in video is sufficient then all you need is the buttons

      Where you would pass instance which contains what the sample checkout as part of the instance variable this would be all relevant input, all providers paypal, stripe & square have been fully implemented to create a customer on their systems which takes all of your users input by this I mean their address etc is also passed to the third party and is also returned in their final response back to you.

      To figure out what variables / parameters are required refer to CartBean

      1. Buttons only feature

      controller/TestController

       /**
       * Test checkout with user who has existing address
       * Action testUser is same as index instead variables come from controller
       * or a service or where ever feeding controller
       * it also attempts to load the first User entry so a user must be setup
       * payment:checkout
       * 
       * The cart items is a flat list of items so if item id:1 is clicked twice it is listed twice
       */
      def testUser() {
       Map instance=[:]
       instance.editCartUrl=g.createLink(controller:'test', action:'checkout')
       //description used by doPayment in PaymentService when finalising sale
       instance.cart=[
               [id:1, name:'item 1', description: 'something',  currency:'GBP', listPrice:1.10],
               [id:2, name:'item 2', description: 'something', currency:'GBP', listPrice:1.00],
               [id:1, name:'item 1',  description: 'something', currency:'GBP', listPrice:1.10],
               [id:1, name:'item 1',  description: 'something', currency:'GBP', listPrice:1.10],
               [id:3, name:'item 3',  description: 'something',currency:'GBP', listPrice:0.50],
               [id:4, name:'item 4',  description: 'something', currency:'GBP', listPrice:0.50],
       ]
       // if you set wrong finalTotal paypal will complain your items above cost is more than your given total
       // you do not need to provide 2 below variables. If not set plugin will figure out based on items in your list above
       //instance.finalTotal=2.50    
       //instance.subTotal=12.50
       
       // optional if you have an existing user set it here at the moment the form will auto fill address details  
       instance.user= PaymentUser?.first()
      
       render view:'testUser', model:[instance:instance]
      }
      
      

      /views/test/testuser <payment:buttons

           <!--CREDIT CART PAYMENT-->
                  <payment:buttons instance="${instance}"  />
      

      Everything the user provides on the checkout page is captured in AddressBean So you need to ensure your instance has the user details / address details set provided your instance should look like:

      You can also provide address details and populate form like this

      /views/test/index.gsp

           <!--CREDIT CART PAYMENT-->
                  <payment:buttons instance="${[
                      currencyCode: 'GBP',  //defaults to PaymentConfig value if not set
                      editCartUrl:g.createLink(controller:'test', action:'checkout'),
                      cart:[
                              [id:1, name:'item 1',  currency:'GBP', listPrice:1.10],
                              [id:2, name:'item 2',  currency:'GBP', listPrice:1.00],
                              [id:1, name:'item 1',  currency:'GBP', listPrice:1.10],
                              [id:1, name:'item 1',  currency:'GBP', listPrice:1.10],
                              [id:3, name:'item 3',  currency:'GBP', listPrice:0.50],
                              [id:4, name:'item 4',  currency:'GBP', listPrice:0.50],
                      ],
                      address:[
                              title:'Mr',
                              firstName:'fred',
                              lastName: 'Smith',
                              line1: '1aaaqqa Long lane',
                              line2: 'Bigaaa street',
                              city: 'London',
                              state:'x',
                              country: 'United Kingdom',
                              countryCode: 'GB',  //should default to set value in PaymentConfig if not set
                              postcode:'se11at',
                              telephone:'12345',
                              emailAddress:'[email protected]',
                              username: '[email protected]',
                              remoteCall:true,
                      ]
              ]
      }" 
                  />
      

      2. Full checkout feature

      controller/TestController

      /**
           * Test checkout
           * Action index: has no variables set
           * index.gsp hard codes parameters set to
           * payment:checkout
           */
          def index() {}
      

      /test/index.gsp <payment:checkout

      Instance is populated in gsp in this case but could be like first example where instance comes from controller. the instance model is quite flexible you can provide everything or as little as possible

      <!doctype html>
      <html>
      <head>
          <meta name="layout" content="main"/>
          <title>Welcome to Grails</title>
      </head>
      <body>
      <h4><g:render template="menu"/></h4>
      <payment:checkout instance="[
              editCartUrl:g.createLink(controller:'test', action:'checkout'),
              cart:[
                      [id:1, name:'item 1',  currency:'GBP', listPrice:1.10],
                      [id:2, name:'item 2',  currency:'GBP', listPrice:1.00],
                      [id:1, name:'item 1',  currency:'GBP', listPrice:1.10],
                      [id:1, name:'item 1',  currency:'GBP', listPrice:1.10],
                      [id:3, name:'item 3',  currency:'GBP', listPrice:0.50],
                      [id:4, name:'item 4',  currency:'GBP', listPrice:0.50],
              ],
             
      ]"
      />
      </body>
      </html>
      
      

      For buttons you could probably get away as per example with just the user details and a finalTotal so if you are just capturing a charge maybe a donation without cart items you could follow this example:

      <payment:buttons instance="${[
              // this buttons instance has no cart items just a total
              finalTotal: 1.00,  //override calculation from cart items below with your own final figure
              currencyCode: 'GBP',  //defaults to PaymentConfig value if not set
              editCartUrl:g.createLink(controller:'test', action:'checkout'),
              address:[
                      title:'Mr',
                      firstName:'fred from gsp',
                      lastName: 'Smith in GSP',
                      line1: '1 GSP Page',
                      line2: 'set by gsp',
                      city: 'GrailsServerPage',
                      state:'GSP State',
                      country: 'United Kingdom',
                      countryCode: 'GB',  //should default to set value in PaymentConfig if not set
                      postcode:'se11at',
                      username: '[email protected]',
                      remoteCall:true,
                      telephone:'12345',
                      emailAddress:'[email protected]',
      
              ]
      ]}"
      />
      

      Address binding some variables explained:

      If no username is provided it will set it or use emailAddress as username The remoteCall is a new variable introduced and if you wish to override username taken errors set this to true so in case of buttons it will seamlessly work with existing users who placed orders etc

      The plugin will try to logically work out if a given set of details is a true match to existing data. If user is an existing user and the address details of line1 and line2 are identical then it will load up the existing user If it's an existing user but the address details a different then in typical checkout mode it would complain username is taken with buttons mode you can enable remoteCall:true the system will know to generate an alternative unused username to allow a new sign up to complete sale. So perhaps in the case of buttons you want to enable this feature.

       address:[
          ..
          //By default false
          remoteCall:true  
          //by default false
          saveInfo:true 
          
          emailAddress='[email protected]'  
          username=''
          ]
      

      The CartBean has a load more inputs most of it set by system. The above example is the basic parameters and format required to be posted for buttons to actually post correct information to selected provider. Front end currently asks for password and confirmation this is because it came from a template that signed up user onto system via spring security, this plugin does not provide spring security

      The buttons use vanilla JavaScript to control the basic stuff that it does, it is all to give you an idea The buttons and processes can be tweaked by copying locally and updating.

      By all means if you improve plugin get in touch and improve for everyone else too

      Paypal steps:

      Step 1 paypalcheckout

      Step 2 uploadCart

      Step 3 execute

      step 4 cancel/thanks

      Square steps:

      Step 1 squarecheckout

      step 2 thanks

      Stripe steps:

      Step 1 stripecheckout

      Step 2 thanks

      Sample Controller / views

      HoMEmenuCopyrights 2015.All rights reserved.More welcome - Collect from power by english Blok number sss85786789633111 Copyright