fintecture 0.1.8 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.gitignore +17 -16
 - data/.rspec +3 -3
 - data/.travis.yml +7 -7
 - data/CODE_OF_CONDUCT.md +74 -74
 - data/Gemfile +8 -6
 - data/Gemfile.lock +22 -3
 - data/LICENSE.txt +674 -674
 - data/README.md +404 -121
 - data/Rakefile +8 -6
 - data/bin/console +15 -14
 - data/bin/setup +8 -8
 - data/exemples/ais.rb +53 -0
 - data/exemples/config_ais.json +8 -0
 - data/exemples/config_pis.json +6 -0
 - data/exemples/pis.rb +148 -0
 - data/exemples/ressources.rb +23 -0
 - data/fintecture.gemspec +44 -43
 - data/lib/fintecture/ais_client.rb +94 -0
 - data/lib/fintecture/api/ais/account_holders.rb +61 -0
 - data/lib/fintecture/api/ais/accounts.rb +63 -0
 - data/lib/fintecture/api/ais/authorize.rb +72 -0
 - data/lib/fintecture/api/ais/authorize_decoupled.rb +68 -0
 - data/lib/fintecture/api/ais/connect.rb +65 -0
 - data/lib/fintecture/api/ais/delete_customer.rb +53 -0
 - data/lib/fintecture/api/ais/transactions.rb +64 -0
 - data/lib/fintecture/{authentication.rb → api/auth/authentication.rb} +78 -76
 - data/lib/fintecture/api/pis/connect.rb +77 -0
 - data/lib/fintecture/api/pis/initiate.rb +52 -0
 - data/lib/fintecture/api/pis/payments.rb +48 -0
 - data/lib/fintecture/api/pis/refund.rb +67 -0
 - data/lib/fintecture/api/pis/request_to_pay.rb +63 -0
 - data/lib/fintecture/api/pis/settlements.rb +48 -0
 - data/lib/fintecture/api/ressources/applications.rb +57 -0
 - data/lib/fintecture/api/ressources/providers.rb +61 -0
 - data/lib/fintecture/api/ressources/test_accounts.rb +60 -0
 - data/lib/fintecture/base_url.rb +26 -0
 - data/lib/fintecture/endpoints/ais.rb +17 -0
 - data/lib/fintecture/{api/endpoints → endpoints}/authentication.rb +13 -13
 - data/lib/fintecture/endpoints/pis.rb +16 -0
 - data/lib/fintecture/endpoints/ressources.rb +13 -0
 - data/lib/fintecture/exceptions.rb +72 -4
 - data/lib/fintecture/faraday/authentication/connection.rb +140 -74
 - data/lib/fintecture/pis_client.rb +100 -0
 - data/lib/fintecture/utils/constants.rb +11 -14
 - data/lib/fintecture/utils/crypto.rb +75 -76
 - data/lib/fintecture/utils/date.rb +15 -15
 - data/lib/fintecture/utils/validation.rb +32 -17
 - data/lib/fintecture/version.rb +5 -3
 - data/lib/fintecture.rb +65 -82
 - metadata +35 -13
 - data/lib/fintecture/api/base_url.rb +0 -28
 - data/lib/fintecture/api/endpoints/pis.rb +0 -13
 - data/lib/fintecture/connect.rb +0 -173
 - data/lib/fintecture/pis.rb +0 -61
 
    
        data/exemples/pis.rb
    ADDED
    
    | 
         @@ -0,0 +1,148 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require './lib/fintecture'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            config = JSON.parse(File.read('./exemples/config_pis.json'))
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            pis_client = Fintecture::PisClient.new({
         
     | 
| 
      
 8 
     | 
    
         
            +
                                                     environment: config['environment'],
         
     | 
| 
      
 9 
     | 
    
         
            +
                                                     app_id: config['app_id'],
         
     | 
| 
      
 10 
     | 
    
         
            +
                                                     app_secret: config['app_secret'],
         
     | 
| 
      
 11 
     | 
    
         
            +
                                                     private_key: config['private_key']
         
     | 
| 
      
 12 
     | 
    
         
            +
                                                   })
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            payload_connect = {
         
     | 
| 
      
 15 
     | 
    
         
            +
              meta: {
         
     | 
| 
      
 16 
     | 
    
         
            +
                psu_name: 'John Doe', # Mandatory
         
     | 
| 
      
 17 
     | 
    
         
            +
                psu_email: 'John.Doe@gmail.com', # Mandatory
         
     | 
| 
      
 18 
     | 
    
         
            +
                psu_phone: '666777888', # Mandatory
         
     | 
| 
      
 19 
     | 
    
         
            +
                psu_phone_prefix: '', # Optionnal
         
     | 
| 
      
 20 
     | 
    
         
            +
                psu_ip: '127.0.0.1', # Optionnal (Plante la signature)
         
     | 
| 
      
 21 
     | 
    
         
            +
                psu_form: '', # Mandatory - if no fixed beneficiary
         
     | 
| 
      
 22 
     | 
    
         
            +
                psu_incorporation: '', # Mandatory - if no fixed beneficiary
         
     | 
| 
      
 23 
     | 
    
         
            +
                psu_address: {
         
     | 
| 
      
 24 
     | 
    
         
            +
                  street: 'Main St.', # Mandatory
         
     | 
| 
      
 25 
     | 
    
         
            +
                  # number: '123', # Optional
         
     | 
| 
      
 26 
     | 
    
         
            +
                  complement: '2nd floor', # Optional
         
     | 
| 
      
 27 
     | 
    
         
            +
                  city: 'Paris', # Mandatory
         
     | 
| 
      
 28 
     | 
    
         
            +
                  zip: '75000', # Mandatory
         
     | 
| 
      
 29 
     | 
    
         
            +
                  country: 'fr' # Mandatory
         
     | 
| 
      
 30 
     | 
    
         
            +
                }
         
     | 
| 
      
 31 
     | 
    
         
            +
              },
         
     | 
| 
      
 32 
     | 
    
         
            +
              data: {
         
     | 
| 
      
 33 
     | 
    
         
            +
                type: 'PIS',
         
     | 
| 
      
 34 
     | 
    
         
            +
                attributes: {
         
     | 
| 
      
 35 
     | 
    
         
            +
                  amount: '123', # Mandatory
         
     | 
| 
      
 36 
     | 
    
         
            +
                  currency: 'EUR', # Mandatory
         
     | 
| 
      
 37 
     | 
    
         
            +
                  communication: 'Thanks Mom!' # Mandatory
         
     | 
| 
      
 38 
     | 
    
         
            +
                  # execution_date: '2021-09-31', # Optional
         
     | 
| 
      
 39 
     | 
    
         
            +
                  # beneficiary: {      # Optional
         
     | 
| 
      
 40 
     | 
    
         
            +
                  #     name: "Dummy SA", # Conditional
         
     | 
| 
      
 41 
     | 
    
         
            +
                  #     iban: "FR1420041010050500013M02606", # Conditional
         
     | 
| 
      
 42 
     | 
    
         
            +
                  #     swift_bic: "FTSBSESSXXX", # Conditional
         
     | 
| 
      
 43 
     | 
    
         
            +
                  #     street: "road of somewhere", # Conditional
         
     | 
| 
      
 44 
     | 
    
         
            +
                  #     number: "2", # Optional
         
     | 
| 
      
 45 
     | 
    
         
            +
                  #     complement:"", # Optional
         
     | 
| 
      
 46 
     | 
    
         
            +
                  #     city: "Paris", # Conditional
         
     | 
| 
      
 47 
     | 
    
         
            +
                  #     zip: "93160", # Conditional
         
     | 
| 
      
 48 
     | 
    
         
            +
                  #     country: "FR", # Conditional
         
     | 
| 
      
 49 
     | 
    
         
            +
                  #     form: "", # Mandatory if no fixed beneficiary
         
     | 
| 
      
 50 
     | 
    
         
            +
                  #     incorporation: "" # Mandatory if no fixed beneficiary
         
     | 
| 
      
 51 
     | 
    
         
            +
                  # },
         
     | 
| 
      
 52 
     | 
    
         
            +
                  # debited_account_id: 'FR1420041010050500013M02606', # Optional
         
     | 
| 
      
 53 
     | 
    
         
            +
                  # debited_account_type: 'iban', # Mandatory if debited_account_id exist
         
     | 
| 
      
 54 
     | 
    
         
            +
                  # end_to_end_id: '5f78e902907e4209aa8df63659b05d24',
         
     | 
| 
      
 55 
     | 
    
         
            +
                  # scheme: 'AUTO' # Optional
         
     | 
| 
      
 56 
     | 
    
         
            +
                }
         
     | 
| 
      
 57 
     | 
    
         
            +
              }
         
     | 
| 
      
 58 
     | 
    
         
            +
            }
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            payload_request_to_pay = {
         
     | 
| 
      
 61 
     | 
    
         
            +
              meta: {
         
     | 
| 
      
 62 
     | 
    
         
            +
                psu_name: 'John Doe', # Mandatory
         
     | 
| 
      
 63 
     | 
    
         
            +
                psu_email: 'John.Doe@gmail.com', # Mandatory
         
     | 
| 
      
 64 
     | 
    
         
            +
                psu_phone: '666777888', # Mandatory
         
     | 
| 
      
 65 
     | 
    
         
            +
                psu_phone_prefix: '+33', # Optionnal
         
     | 
| 
      
 66 
     | 
    
         
            +
                psu_address: {
         
     | 
| 
      
 67 
     | 
    
         
            +
                  street: 'Main St.', # Mandatory
         
     | 
| 
      
 68 
     | 
    
         
            +
                  number: '123', # Optional
         
     | 
| 
      
 69 
     | 
    
         
            +
                  city: 'Paris', # Mandatory
         
     | 
| 
      
 70 
     | 
    
         
            +
                  zip: '75000', # Mandatory
         
     | 
| 
      
 71 
     | 
    
         
            +
                  country: 'fr' # Mandatory
         
     | 
| 
      
 72 
     | 
    
         
            +
                },
         
     | 
| 
      
 73 
     | 
    
         
            +
                expirary: 86_400, # Optional
         
     | 
| 
      
 74 
     | 
    
         
            +
                cc: 'John.Doe@gmail.com', # Optional
         
     | 
| 
      
 75 
     | 
    
         
            +
                bcc: 'John.Doe@gmail.com' # Optional
         
     | 
| 
      
 76 
     | 
    
         
            +
              },
         
     | 
| 
      
 77 
     | 
    
         
            +
              data: {
         
     | 
| 
      
 78 
     | 
    
         
            +
                type: 'REQUEST_TO_PAY',
         
     | 
| 
      
 79 
     | 
    
         
            +
                attributes: {
         
     | 
| 
      
 80 
     | 
    
         
            +
                  amount: 123, # Mandatory
         
     | 
| 
      
 81 
     | 
    
         
            +
                  currency: 'EUR', # Mandatory
         
     | 
| 
      
 82 
     | 
    
         
            +
                  communication: 'Thanks Mom!' # Mandatory
         
     | 
| 
      
 83 
     | 
    
         
            +
                }
         
     | 
| 
      
 84 
     | 
    
         
            +
              }
         
     | 
| 
      
 85 
     | 
    
         
            +
            }
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
            payload_initiate = {
         
     | 
| 
      
 88 
     | 
    
         
            +
              "meta": {
         
     | 
| 
      
 89 
     | 
    
         
            +
                "psu_name": 'Bob McCheese',
         
     | 
| 
      
 90 
     | 
    
         
            +
                "psu_email": 'John.Doe@gmail.com',
         
     | 
| 
      
 91 
     | 
    
         
            +
                "psu_phone": '09743593535',
         
     | 
| 
      
 92 
     | 
    
         
            +
                "psu_address": {
         
     | 
| 
      
 93 
     | 
    
         
            +
                  "street": 'route de la france',
         
     | 
| 
      
 94 
     | 
    
         
            +
                  "number": '33',
         
     | 
| 
      
 95 
     | 
    
         
            +
                  "complement": '2nd floor',
         
     | 
| 
      
 96 
     | 
    
         
            +
                  "zip": '12001',
         
     | 
| 
      
 97 
     | 
    
         
            +
                  "city": 'Paris',
         
     | 
| 
      
 98 
     | 
    
         
            +
                  "country": 'FR'
         
     | 
| 
      
 99 
     | 
    
         
            +
                }
         
     | 
| 
      
 100 
     | 
    
         
            +
              },
         
     | 
| 
      
 101 
     | 
    
         
            +
              "data": {
         
     | 
| 
      
 102 
     | 
    
         
            +
                "type": 'PIS',
         
     | 
| 
      
 103 
     | 
    
         
            +
                "attributes": {
         
     | 
| 
      
 104 
     | 
    
         
            +
                  "amount": '149.30',
         
     | 
| 
      
 105 
     | 
    
         
            +
                  "currency": 'EUR',
         
     | 
| 
      
 106 
     | 
    
         
            +
                  "communication": 'Order 6543321'
         
     | 
| 
      
 107 
     | 
    
         
            +
                  # "beneficiary": {
         
     | 
| 
      
 108 
     | 
    
         
            +
                  #     "name": "Bob Smith",
         
     | 
| 
      
 109 
     | 
    
         
            +
                  #     "street": "road of somewhere",
         
     | 
| 
      
 110 
     | 
    
         
            +
                  #     "number": "2",
         
     | 
| 
      
 111 
     | 
    
         
            +
                  #     "city": "Paris",
         
     | 
| 
      
 112 
     | 
    
         
            +
                  #     "zip": "93160",
         
     | 
| 
      
 113 
     | 
    
         
            +
                  #     "country": "FR",
         
     | 
| 
      
 114 
     | 
    
         
            +
                  #     "iban": "FR1420041010050500013M02606",
         
     | 
| 
      
 115 
     | 
    
         
            +
                  #     "swift_bic": "BANKFRXXXXX"
         
     | 
| 
      
 116 
     | 
    
         
            +
                  # }
         
     | 
| 
      
 117 
     | 
    
         
            +
                }
         
     | 
| 
      
 118 
     | 
    
         
            +
              }
         
     | 
| 
      
 119 
     | 
    
         
            +
            }
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
            paramsProviders = {
         
     | 
| 
      
 122 
     | 
    
         
            +
              'filter[country]': 'FR',
         
     | 
| 
      
 123 
     | 
    
         
            +
              'filter[pis]': 'SEPA',
         
     | 
| 
      
 124 
     | 
    
         
            +
              'filter[ais]': 'Accounts',
         
     | 
| 
      
 125 
     | 
    
         
            +
              'filter[psu_type]': 'retail',
         
     | 
| 
      
 126 
     | 
    
         
            +
              'filter[auth_model]': 'redirect',
         
     | 
| 
      
 127 
     | 
    
         
            +
              'sort[name]': 'ASC',
         
     | 
| 
      
 128 
     | 
    
         
            +
              'sort[full_name]': 'ASC',
         
     | 
| 
      
 129 
     | 
    
         
            +
              'sort[country]': 'ASC',
         
     | 
| 
      
 130 
     | 
    
         
            +
              'sort[provider_id]': 'ASC'
         
     | 
| 
      
 131 
     | 
    
         
            +
            }
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
            # ######################## PIS ########################
         
     | 
| 
      
 134 
     | 
    
         
            +
            # ------------ Get access token ------------
         
     | 
| 
      
 135 
     | 
    
         
            +
            pis_client.generate_token
         
     | 
| 
      
 136 
     | 
    
         
            +
            # ------------ Connect ------------
         
     | 
| 
      
 137 
     | 
    
         
            +
            puts pis_client.connect payload_connect, 'ok', 'https://www.google.fr'
         
     | 
| 
      
 138 
     | 
    
         
            +
            # ------------ Request to pay ------------
         
     | 
| 
      
 139 
     | 
    
         
            +
            puts pis_client.request_to_pay payload_request_to_pay, 'fr', 'https://www.google.fr'
         
     | 
| 
      
 140 
     | 
    
         
            +
            # ------------ Get payments ------------
         
     | 
| 
      
 141 
     | 
    
         
            +
            puts pis_client.payments '7f47d3675f5d4964bc416b43af63b06e'
         
     | 
| 
      
 142 
     | 
    
         
            +
            # ------------ Initiate ------------
         
     | 
| 
      
 143 
     | 
    
         
            +
            puts pis_client.initiate payload_initiate, 'cmcifrpp', 'https://www.google.fr', 'ok'
         
     | 
| 
      
 144 
     | 
    
         
            +
            # ------------ Refund ------------
         
     | 
| 
      
 145 
     | 
    
         
            +
            puts pis_client.refund '7f47d3675f5d4964bc416b43af63b06e', 1
         
     | 
| 
      
 146 
     | 
    
         
            +
            # ------------ settlements ------------
         
     | 
| 
      
 147 
     | 
    
         
            +
            pis_client.settlements
         
     | 
| 
      
 148 
     | 
    
         
            +
            pis_client.settlements '127335fdeb073e0eb2313ba0bd71ad44'
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require './lib/fintecture'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            # ------------ Test class -------------
         
     | 
| 
      
 6 
     | 
    
         
            +
            config = JSON.parse(File.read('./exemples/config_pis.json'))
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            pis_client = Fintecture::PisClient.new({
         
     | 
| 
      
 9 
     | 
    
         
            +
                                                     environment: config['environment'],
         
     | 
| 
      
 10 
     | 
    
         
            +
                                                     app_id: config['app_id'],
         
     | 
| 
      
 11 
     | 
    
         
            +
                                                     app_secret: config['app_secret'],
         
     | 
| 
      
 12 
     | 
    
         
            +
                                                     private_key: config['private_key']
         
     | 
| 
      
 13 
     | 
    
         
            +
                                                   })
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            # ######################## RESSOURCES ########################
         
     | 
| 
      
 16 
     | 
    
         
            +
            # ------------ Get providers ------------
         
     | 
| 
      
 17 
     | 
    
         
            +
            puts pis_client.providers provider_id: 'agfbfr'
         
     | 
| 
      
 18 
     | 
    
         
            +
            puts pis_client.providers paramsProviders: paramsProviders
         
     | 
| 
      
 19 
     | 
    
         
            +
            # ------------ Get applications ------------
         
     | 
| 
      
 20 
     | 
    
         
            +
            puts pis_client.applications
         
     | 
| 
      
 21 
     | 
    
         
            +
            # ------------ Get test accounts ------------
         
     | 
| 
      
 22 
     | 
    
         
            +
            puts pis_client.test_accounts
         
     | 
| 
      
 23 
     | 
    
         
            +
            puts pis_client.test_accounts 'bbvaes'
         
     | 
    
        data/fintecture.gemspec
    CHANGED
    
    | 
         @@ -1,43 +1,44 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              spec. 
     | 
| 
       9 
     | 
    
         
            -
              spec. 
     | 
| 
       10 
     | 
    
         
            -
              spec. 
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
              spec. 
     | 
| 
       14 
     | 
    
         
            -
              spec. 
     | 
| 
       15 
     | 
    
         
            -
              spec. 
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
              #  
     | 
| 
       19 
     | 
    
         
            -
               
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                spec.metadata[ 
     | 
| 
       24 
     | 
    
         
            -
                 
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
              #  
     | 
| 
       32 
     | 
    
         
            -
               
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
               
     | 
| 
       36 
     | 
    
         
            -
              spec. 
     | 
| 
       37 
     | 
    
         
            -
              spec. 
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              spec.add_development_dependency  
     | 
| 
       41 
     | 
    
         
            -
              spec.add_development_dependency  
     | 
| 
       42 
     | 
    
         
            -
              spec. 
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            lib = File.expand_path('lib', __dir__)
         
     | 
| 
      
 4 
     | 
    
         
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'fintecture/version'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            Gem::Specification.new do |spec|
         
     | 
| 
      
 8 
     | 
    
         
            +
              spec.name          = 'fintecture'
         
     | 
| 
      
 9 
     | 
    
         
            +
              spec.version       = Fintecture::VERSION
         
     | 
| 
      
 10 
     | 
    
         
            +
              spec.authors       = ['Fintecture']
         
     | 
| 
      
 11 
     | 
    
         
            +
              spec.email         = ['alvaro.fernandez@nazaries.com']
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              spec.summary       = 'Short summary'
         
     | 
| 
      
 14 
     | 
    
         
            +
              spec.description   = 'Longer summary'
         
     | 
| 
      
 15 
     | 
    
         
            +
              spec.homepage      = 'http://fintecture.com'
         
     | 
| 
      
 16 
     | 
    
         
            +
              spec.license       = 'GPL-3.0'
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
         
     | 
| 
      
 19 
     | 
    
         
            +
              # to allow pushing to a single host or delete this section to allow pushing to any host.
         
     | 
| 
      
 20 
     | 
    
         
            +
              if spec.respond_to?(:metadata)
         
     | 
| 
      
 21 
     | 
    
         
            +
                # spec.metadata["allowed_push_host"] = 'http://mygemserver.com'
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                spec.metadata['homepage_uri'] = spec.homepage
         
     | 
| 
      
 24 
     | 
    
         
            +
                spec.metadata['source_code_uri'] = 'https://github.com/Fintecture/fintecture-sdk-ruby'
         
     | 
| 
      
 25 
     | 
    
         
            +
                # spec.metadata["changelog_uri"] = spec.homepage
         
     | 
| 
      
 26 
     | 
    
         
            +
              else
         
     | 
| 
      
 27 
     | 
    
         
            +
                raise 'RubyGems 2.0 or newer is required to protect against ' \
         
     | 
| 
      
 28 
     | 
    
         
            +
                  'public gem pushes.'
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              # Specify which files should be added to the gem when it is released.
         
     | 
| 
      
 32 
     | 
    
         
            +
              # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
         
     | 
| 
      
 33 
     | 
    
         
            +
              spec.files = Dir.chdir(File.expand_path(__dir__)) do
         
     | 
| 
      
 34 
     | 
    
         
            +
                `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
              spec.bindir        = 'exe'
         
     | 
| 
      
 37 
     | 
    
         
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         
     | 
| 
      
 38 
     | 
    
         
            +
              spec.require_paths = ['lib']
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              spec.add_development_dependency 'bundler', '~> 2.0'
         
     | 
| 
      
 41 
     | 
    
         
            +
              spec.add_development_dependency 'rake', '~> 10.0'
         
     | 
| 
      
 42 
     | 
    
         
            +
              spec.add_development_dependency 'rspec', '~> 3.0'
         
     | 
| 
      
 43 
     | 
    
         
            +
              spec.add_dependency 'faraday'
         
     | 
| 
      
 44 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,94 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'fintecture/api/ais/connect'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'fintecture/api/ais/accounts'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'fintecture/api/ais/transactions'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'fintecture/api/ais/account_holders'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'fintecture/api/ais/delete_customer'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'fintecture/api/ais/authorize'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'fintecture/api/ais/authorize_decoupled'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            module Fintecture
         
     | 
| 
      
 12 
     | 
    
         
            +
              class AisClient
         
     | 
| 
      
 13 
     | 
    
         
            +
                @environment = 'sandbox'
         
     | 
| 
      
 14 
     | 
    
         
            +
                @environments = %w[local sandbox production].freeze
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                def initialize(config)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @app_id = config[:app_id]
         
     | 
| 
      
 18 
     | 
    
         
            +
                  @app_secret = config[:app_secret]
         
     | 
| 
      
 19 
     | 
    
         
            +
                  @private_key = config[:private_key]
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  environment = config[:environment].downcase
         
     | 
| 
      
 22 
     | 
    
         
            +
                  unless environment.include?(environment)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    raise "#{environment} not a valid environment, options are [#{environment.join(', ')}]"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  @environment = environment
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                # Getters
         
     | 
| 
      
 30 
     | 
    
         
            +
                attr_reader :app_id, :app_secret, :private_key, :environment, :token, :token_expires_in, :refresh_token
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                #  Methodes
         
     | 
| 
      
 33 
     | 
    
         
            +
                def connect(state, redirect_uri, scope = nil)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  res = Fintecture::Ais::Connect.generate self, state, redirect_uri, scope
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  JSON.parse res.body
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                def generate_token(auth_code)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  res = Fintecture::Authentication.get_access_token self, auth_code
         
     | 
| 
      
 41 
     | 
    
         
            +
                  body = JSON.parse res.body
         
     | 
| 
      
 42 
     | 
    
         
            +
                  @token = body['access_token']
         
     | 
| 
      
 43 
     | 
    
         
            +
                  @token_expires_in = body['expires_in']
         
     | 
| 
      
 44 
     | 
    
         
            +
                  @refresh_token = body['refresh_token']
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  body
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                def generate_refresh_token(refresh_token = nil)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  res = Fintecture::Authentication.refresh_token self, (refresh_token || @refresh_token)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  body = JSON.parse res.body
         
     | 
| 
      
 52 
     | 
    
         
            +
                  @token = body['access_token']
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  body
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                def accounts(customer_id:, account_id: nil, remove_nulls: nil, withBalances: nil)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  res = Fintecture::Ais::Accounts.get self, customer_id, account_id, remove_nulls, withBalances
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  JSON.parse res.body
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                def transactions(customer_id:, account_id:, remove_nulls: nil, convert_dates: nil, filters: nil)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  res = Fintecture::Ais::Transactions.get self, customer_id, account_id, remove_nulls, convert_dates, filters
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                  JSON.parse res.body
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                def account_holders(customer_id:, remove_nulls: nil)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  res = Fintecture::Ais::AccountHolders.get self, customer_id, remove_nulls
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                  JSON.parse res.body
         
     | 
| 
      
 73 
     | 
    
         
            +
                end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                def delete_customer(customer_id:)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  res = Fintecture::Ais::DeleteCustomer.delete self, customer_id
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                  JSON.parse res.body
         
     | 
| 
      
 79 
     | 
    
         
            +
                end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                def authorize(provider_id:, redirect_uri:, app_id_auth: false, state: nil, x_psu_id: nil, x_psu_ip_address: nil)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  res = Fintecture::Ais::Authorize.get self, app_id_auth, provider_id, redirect_uri, state, x_psu_id,
         
     | 
| 
      
 83 
     | 
    
         
            +
                                                       x_psu_ip_address
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  JSON.parse res.body
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                def authorize_decoupled(provider_id:, polling_id:, app_id_auth: false)
         
     | 
| 
      
 89 
     | 
    
         
            +
                  res = Fintecture::Ais::AuthorizeDecoupled.get self, app_id_auth, provider_id, polling_id
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                  JSON.parse res.body
         
     | 
| 
      
 92 
     | 
    
         
            +
                end
         
     | 
| 
      
 93 
     | 
    
         
            +
              end
         
     | 
| 
      
 94 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,61 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'base64'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'faraday'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'fintecture/utils/validation'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'fintecture/exceptions'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'fintecture/utils/date'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'fintecture/utils/constants'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            module Fintecture
         
     | 
| 
      
 12 
     | 
    
         
            +
              module Ais
         
     | 
| 
      
 13 
     | 
    
         
            +
                class AccountHolders
         
     | 
| 
      
 14 
     | 
    
         
            +
                  class << self
         
     | 
| 
      
 15 
     | 
    
         
            +
                    # ------------ PUBLIC METHOD ------------
         
     | 
| 
      
 16 
     | 
    
         
            +
                    def get(client, customer_id, remove_nulls)
         
     | 
| 
      
 17 
     | 
    
         
            +
                      @client = client
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                      # Do the request
         
     | 
| 
      
 20 
     | 
    
         
            +
                      _request customer_id, remove_nulls
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                    private
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    # ------------ REQUEST ------------
         
     | 
| 
      
 26 
     | 
    
         
            +
                    def _request(customer_id, remove_nulls)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      # Get the url request
         
     | 
| 
      
 28 
     | 
    
         
            +
                      url = _endpoint customer_id
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                      # Build uri params
         
     | 
| 
      
 31 
     | 
    
         
            +
                      query_string = ''
         
     | 
| 
      
 32 
     | 
    
         
            +
                      if remove_nulls
         
     | 
| 
      
 33 
     | 
    
         
            +
                        params = {}
         
     | 
| 
      
 34 
     | 
    
         
            +
                        params['remove_nulls'] = remove_nulls if remove_nulls
         
     | 
| 
      
 35 
     | 
    
         
            +
                        query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
         
     | 
| 
      
 36 
     | 
    
         
            +
                      end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                      # Do connect request
         
     | 
| 
      
 39 
     | 
    
         
            +
                      Fintecture::Faraday::Authentication::Connection.get(
         
     | 
| 
      
 40 
     | 
    
         
            +
                        url: url + query_string,
         
     | 
| 
      
 41 
     | 
    
         
            +
                        client: @client,
         
     | 
| 
      
 42 
     | 
    
         
            +
                        custom_content_type: 'application/json',
         
     | 
| 
      
 43 
     | 
    
         
            +
                        bearer: "Bearer #{@client.token}",
         
     | 
| 
      
 44 
     | 
    
         
            +
                        secure_headers: true
         
     | 
| 
      
 45 
     | 
    
         
            +
                      )
         
     | 
| 
      
 46 
     | 
    
         
            +
                    end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                    # ------------ API ENDPOINT ------------
         
     | 
| 
      
 49 
     | 
    
         
            +
                    def _endpoint(customer_id)
         
     | 
| 
      
 50 
     | 
    
         
            +
                      "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::ACCOUNTHOLDERS}/#{customer_id}/accountholders"
         
     | 
| 
      
 51 
     | 
    
         
            +
                    end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                    # ------------ BASE URL ------------
         
     | 
| 
      
 54 
     | 
    
         
            +
                    def _api_base_url
         
     | 
| 
      
 55 
     | 
    
         
            +
                      Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,63 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'base64'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'faraday'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'fintecture/utils/validation'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'fintecture/exceptions'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'fintecture/utils/date'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'fintecture/utils/constants'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            module Fintecture
         
     | 
| 
      
 12 
     | 
    
         
            +
              module Ais
         
     | 
| 
      
 13 
     | 
    
         
            +
                class Accounts
         
     | 
| 
      
 14 
     | 
    
         
            +
                  class << self
         
     | 
| 
      
 15 
     | 
    
         
            +
                    # ------------ PUBLIC METHOD ------------
         
     | 
| 
      
 16 
     | 
    
         
            +
                    def get(client, customer_id, account_id, remove_nulls, withBalances)
         
     | 
| 
      
 17 
     | 
    
         
            +
                      @client = client
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                      # Do the request
         
     | 
| 
      
 20 
     | 
    
         
            +
                      _request customer_id, account_id, remove_nulls, withBalances
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                    private
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    # ------------ REQUEST ------------
         
     | 
| 
      
 26 
     | 
    
         
            +
                    def _request(customer_id, account_id, remove_nulls, withBalances)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      # Get the url request
         
     | 
| 
      
 28 
     | 
    
         
            +
                      url = _endpoint customer_id, account_id
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                      # Build uri params
         
     | 
| 
      
 31 
     | 
    
         
            +
                      query_string = ''
         
     | 
| 
      
 32 
     | 
    
         
            +
                      if remove_nulls || withBalances
         
     | 
| 
      
 33 
     | 
    
         
            +
                        params = {}
         
     | 
| 
      
 34 
     | 
    
         
            +
                        params['remove_nulls'] = remove_nulls if remove_nulls
         
     | 
| 
      
 35 
     | 
    
         
            +
                        params['withBalances'] = withBalances if withBalances
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                        query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
         
     | 
| 
      
 38 
     | 
    
         
            +
                      end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                      # Do connect request
         
     | 
| 
      
 41 
     | 
    
         
            +
                      Fintecture::Faraday::Authentication::Connection.get(
         
     | 
| 
      
 42 
     | 
    
         
            +
                        url: url + query_string,
         
     | 
| 
      
 43 
     | 
    
         
            +
                        client: @client,
         
     | 
| 
      
 44 
     | 
    
         
            +
                        custom_content_type: 'application/json',
         
     | 
| 
      
 45 
     | 
    
         
            +
                        bearer: "Bearer #{@client.token}",
         
     | 
| 
      
 46 
     | 
    
         
            +
                        secure_headers: true
         
     | 
| 
      
 47 
     | 
    
         
            +
                      )
         
     | 
| 
      
 48 
     | 
    
         
            +
                    end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                    # ------------ API ENDPOINT ------------
         
     | 
| 
      
 51 
     | 
    
         
            +
                    def _endpoint(customer_id, account_id)
         
     | 
| 
      
 52 
     | 
    
         
            +
                      "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::ACCOUNTS}/#{customer_id}/accounts/#{account_id || ''}"
         
     | 
| 
      
 53 
     | 
    
         
            +
                    end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                    # ------------ BASE URL ------------
         
     | 
| 
      
 56 
     | 
    
         
            +
                    def _api_base_url
         
     | 
| 
      
 57 
     | 
    
         
            +
                      Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
         
     | 
| 
      
 58 
     | 
    
         
            +
                    end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  end
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,72 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'base64'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'faraday'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'fintecture/utils/validation'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'fintecture/exceptions'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'fintecture/utils/date'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'fintecture/utils/constants'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            module Fintecture
         
     | 
| 
      
 12 
     | 
    
         
            +
              module Ais
         
     | 
| 
      
 13 
     | 
    
         
            +
                class Authorize
         
     | 
| 
      
 14 
     | 
    
         
            +
                  class << self
         
     | 
| 
      
 15 
     | 
    
         
            +
                    # ------------ PUBLIC METHOD ------------
         
     | 
| 
      
 16 
     | 
    
         
            +
                    def get(client, app_id_auth, provider_id, redirect_uri, state, x_psu_id, x_psu_ip_address)
         
     | 
| 
      
 17 
     | 
    
         
            +
                      @client = client
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                      # Do the request
         
     | 
| 
      
 20 
     | 
    
         
            +
                      _request app_id_auth, provider_id, redirect_uri, state, x_psu_id, x_psu_ip_address
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                    private
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    # ------------ REQUEST ------------
         
     | 
| 
      
 26 
     | 
    
         
            +
                    def _request(app_id_auth, provider_id, redirect_uri, state, x_psu_id, x_psu_ip_address)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      # Get the url request
         
     | 
| 
      
 28 
     | 
    
         
            +
                      url = _endpoint provider_id
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                      # Build uri params
         
     | 
| 
      
 31 
     | 
    
         
            +
                      query_string = ''
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                      params = {}
         
     | 
| 
      
 34 
     | 
    
         
            +
                      params['response_type'] = 'code' if app_id_auth
         
     | 
| 
      
 35 
     | 
    
         
            +
                      params['redirect_uri'] = redirect_uri if redirect_uri
         
     | 
| 
      
 36 
     | 
    
         
            +
                      params['state'] = state if state
         
     | 
| 
      
 37 
     | 
    
         
            +
                      params['model'] = 'redirect'
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                      query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                      # Build additional headers
         
     | 
| 
      
 42 
     | 
    
         
            +
                      additional_headers = {}
         
     | 
| 
      
 43 
     | 
    
         
            +
                      additional_headers['app_id'] = @client.app_id if app_id_auth
         
     | 
| 
      
 44 
     | 
    
         
            +
                      additional_headers['x-psu-id'] = x_psu_id if x_psu_id
         
     | 
| 
      
 45 
     | 
    
         
            +
                      additional_headers['x-psu-ip-address'] = x_psu_ip_address if x_psu_ip_address
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                      # Do connect request
         
     | 
| 
      
 48 
     | 
    
         
            +
                      Fintecture::Faraday::Authentication::Connection.get(
         
     | 
| 
      
 49 
     | 
    
         
            +
                        url: url + query_string,
         
     | 
| 
      
 50 
     | 
    
         
            +
                        client: @client,
         
     | 
| 
      
 51 
     | 
    
         
            +
                        custom_content_type: 'application/json',
         
     | 
| 
      
 52 
     | 
    
         
            +
                        bearer: "Bearer #{@client.token}",
         
     | 
| 
      
 53 
     | 
    
         
            +
                        secure_headers: true,
         
     | 
| 
      
 54 
     | 
    
         
            +
                        additional_headers: additional_headers,
         
     | 
| 
      
 55 
     | 
    
         
            +
                        disableAuthorization: app_id_auth ? true : false
         
     | 
| 
      
 56 
     | 
    
         
            +
                      )
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                    # ------------ API ENDPOINT ------------
         
     | 
| 
      
 60 
     | 
    
         
            +
                    def _endpoint(provider_id)
         
     | 
| 
      
 61 
     | 
    
         
            +
                      "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::AUTHORIZE}/#{provider_id}/authorize"
         
     | 
| 
      
 62 
     | 
    
         
            +
                    end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                    # ------------ BASE URL ------------
         
     | 
| 
      
 65 
     | 
    
         
            +
                    def _api_base_url
         
     | 
| 
      
 66 
     | 
    
         
            +
                      Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,68 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'base64'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'faraday'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'fintecture/utils/validation'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'fintecture/exceptions'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'fintecture/utils/date'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'fintecture/utils/constants'
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            module Fintecture
         
     | 
| 
      
 12 
     | 
    
         
            +
              module Ais
         
     | 
| 
      
 13 
     | 
    
         
            +
                class AuthorizeDecoupled
         
     | 
| 
      
 14 
     | 
    
         
            +
                  class << self
         
     | 
| 
      
 15 
     | 
    
         
            +
                    # ------------ PUBLIC METHOD ------------
         
     | 
| 
      
 16 
     | 
    
         
            +
                    def get(client, app_id_auth, provider_id, polling_id)
         
     | 
| 
      
 17 
     | 
    
         
            +
                      @client = client
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                      # Do the request
         
     | 
| 
      
 20 
     | 
    
         
            +
                      _request app_id_auth, provider_id, polling_id
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                    private
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    # ------------ REQUEST ------------
         
     | 
| 
      
 26 
     | 
    
         
            +
                    def _request(app_id_auth, provider_id, polling_id)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      # Get the url request
         
     | 
| 
      
 28 
     | 
    
         
            +
                      url = _endpoint provider_id, polling_id
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                      # Build uri params
         
     | 
| 
      
 31 
     | 
    
         
            +
                      query_string = ''
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                      params = {}
         
     | 
| 
      
 34 
     | 
    
         
            +
                      params['response_type'] = 'code' if app_id_auth
         
     | 
| 
      
 35 
     | 
    
         
            +
                      params['model'] = 'decoupled'
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                      query_string = "?#{params.map { |key, value| "#{key}=#{value}" }.join('&')}"
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                      # Build additional headers
         
     | 
| 
      
 40 
     | 
    
         
            +
                      additional_headers = {}
         
     | 
| 
      
 41 
     | 
    
         
            +
                      additional_headers['app_id'] = @client.app_id if app_id_auth
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                      # Do connect request
         
     | 
| 
      
 44 
     | 
    
         
            +
                      Fintecture::Faraday::Authentication::Connection.get(
         
     | 
| 
      
 45 
     | 
    
         
            +
                        url: url + query_string,
         
     | 
| 
      
 46 
     | 
    
         
            +
                        client: @client,
         
     | 
| 
      
 47 
     | 
    
         
            +
                        custom_content_type: 'application/json',
         
     | 
| 
      
 48 
     | 
    
         
            +
                        bearer: "Bearer #{@client.token}",
         
     | 
| 
      
 49 
     | 
    
         
            +
                        secure_headers: true,
         
     | 
| 
      
 50 
     | 
    
         
            +
                        additional_headers: additional_headers,
         
     | 
| 
      
 51 
     | 
    
         
            +
                        disableAuthorization: app_id_auth ? true : false
         
     | 
| 
      
 52 
     | 
    
         
            +
                      )
         
     | 
| 
      
 53 
     | 
    
         
            +
                    end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                    # ------------ API ENDPOINT ------------
         
     | 
| 
      
 56 
     | 
    
         
            +
                    def _endpoint(provider_id, polling_id)
         
     | 
| 
      
 57 
     | 
    
         
            +
                      "#{_api_base_url}/#{Fintecture::Api::Endpoints::Ais::AUTHORIZE}/#{provider_id}/authorize/decoupled/#{polling_id}"
         
     | 
| 
      
 58 
     | 
    
         
            +
                    end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                    # ------------ BASE URL ------------
         
     | 
| 
      
 61 
     | 
    
         
            +
                    def _api_base_url
         
     | 
| 
      
 62 
     | 
    
         
            +
                      Fintecture::Api::BaseUrl::FINTECTURE_API_URL[@client.environment.to_sym]
         
     | 
| 
      
 63 
     | 
    
         
            +
                    end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                  end
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
            end
         
     |