offsite_payments 2.7.3 → 2.7.4
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
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: fca5c3503aa8268bc5f0b3495a8b610bd79ff955
         | 
| 4 | 
            +
              data.tar.gz: 95634ae04ab55cf706721238b0e30fff074fa4d5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: fe7b2ecbef11e6580b9ba736f92a402d8f8b8270c2b6a76a5192075d31a76757eb92b9d5f8bc340ff236eeb805560a7d5bc5d8bdf76c4a7f56c45d8cd9afa815
         | 
| 7 | 
            +
              data.tar.gz: 4d3377a975972d0255d054749dcd8cbadb54decbd7fe76ebf6ff9fec8a797ed42ad341ca48e28ee1cc0ab227a7103c0552234d2e0722a82c7ed50ad1c60e9d93
         | 
| @@ -30,6 +30,35 @@ module OffsitePayments #:nodoc: | |
| 30 30 | 
             
                    end
         | 
| 31 31 | 
             
                  end
         | 
| 32 32 |  | 
| 33 | 
            +
                  class Helper < OffsitePayments::Helper
         | 
| 34 | 
            +
                    def credential_based_url
         | 
| 35 | 
            +
                      response = request_redirect
         | 
| 36 | 
            +
                      @transaction_id = response['id']
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                      uri = URI.parse(response['links']['paymentUrl'])
         | 
| 39 | 
            +
                      set_form_fields_for_redirect(uri)
         | 
| 40 | 
            +
                      uri.query = ''
         | 
| 41 | 
            +
                      uri.to_s.sub(/\?\z/, '')
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    def form_method
         | 
| 45 | 
            +
                      "GET"
         | 
| 46 | 
            +
                    end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                    private
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    def set_form_fields_for_redirect(uri)
         | 
| 51 | 
            +
                      return unless uri.query
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                      CGI.parse(uri.query).each do |key, value|
         | 
| 54 | 
            +
                        if value.is_a?(Array) && value.length == 1
         | 
| 55 | 
            +
                          add_field(key, value.first)
         | 
| 56 | 
            +
                        else
         | 
| 57 | 
            +
                          add_field(key, value)
         | 
| 58 | 
            +
                        end
         | 
| 59 | 
            +
                      end
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
                  end
         | 
| 33 62 | 
             
                end
         | 
| 34 63 | 
             
              end
         | 
| 35 64 | 
             
            end
         | 
| @@ -61,7 +61,7 @@ module OffsitePayments #:nodoc: | |
| 61 61 | 
             
                    true
         | 
| 62 62 | 
             
                  end
         | 
| 63 63 |  | 
| 64 | 
            -
                  class Helper <  | 
| 64 | 
            +
                  class Helper < Mollie::Helper
         | 
| 65 65 | 
             
                    attr_reader :transaction_id, :redirect_parameters, :token
         | 
| 66 66 |  | 
| 67 67 | 
             
                    def initialize(order, account, options = {})
         | 
| @@ -84,30 +84,6 @@ module OffsitePayments #:nodoc: | |
| 84 84 | 
             
                      raise ArgumentError, "The description option needs to be set." if options[:description].blank?
         | 
| 85 85 | 
             
                    end
         | 
| 86 86 |  | 
| 87 | 
            -
                    def credential_based_url
         | 
| 88 | 
            -
                      response = request_redirect
         | 
| 89 | 
            -
                      @transaction_id = response['id']
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                      uri = URI.parse(response['links']['paymentUrl'])
         | 
| 92 | 
            -
                      set_form_fields_for_redirect(uri)
         | 
| 93 | 
            -
                      uri.query = ''
         | 
| 94 | 
            -
                      uri.to_s.sub(/\?\z/, '')
         | 
| 95 | 
            -
                    end
         | 
| 96 | 
            -
             | 
| 97 | 
            -
                    def form_method
         | 
| 98 | 
            -
                      "GET"
         | 
| 99 | 
            -
                    end
         | 
| 100 | 
            -
             | 
| 101 | 
            -
                    def set_form_fields_for_redirect(uri)
         | 
| 102 | 
            -
                      CGI.parse(uri.query).each do |key, value|
         | 
| 103 | 
            -
                        if value.is_a?(Array) && value.length == 1
         | 
| 104 | 
            -
                          add_field(key, value.first)
         | 
| 105 | 
            -
                        else
         | 
| 106 | 
            -
                          add_field(key, value)
         | 
| 107 | 
            -
                        end
         | 
| 108 | 
            -
                      end
         | 
| 109 | 
            -
                    end
         | 
| 110 | 
            -
             | 
| 111 87 | 
             
                    def request_redirect
         | 
| 112 88 | 
             
                      MollieIdeal.create_payment(token, redirect_parameters)
         | 
| 113 89 | 
             
                    rescue ActiveUtils::ResponseError => e
         | 
| @@ -3,140 +3,130 @@ module OffsitePayments #:nodoc: | |
| 3 3 | 
             
                module MollieMistercash
         | 
| 4 4 | 
             
                  include Mollie
         | 
| 5 5 |  | 
| 6 | 
            -
             | 
| 6 | 
            +
                  RedirectError = Class.new(ActiveUtils::ActiveUtilsError)
         | 
| 7 7 |  | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 8 | 
            +
                  def self.notification(post, options = {})
         | 
| 9 | 
            +
                    Notification.new(post, options)
         | 
| 10 | 
            +
                  end
         | 
| 11 11 |  | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 12 | 
            +
                  def self.return(post, options = {})
         | 
| 13 | 
            +
                    Return.new(post, options)
         | 
| 14 | 
            +
                  end
         | 
| 15 15 |  | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 16 | 
            +
                  def self.live?
         | 
| 17 | 
            +
                    OffsitePayments.mode == :production
         | 
| 18 | 
            +
                  end
         | 
| 19 19 |  | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 20 | 
            +
                  def self.create_payment(token, params)
         | 
| 21 | 
            +
                    API.new(token).post_request('payments', params)
         | 
| 22 | 
            +
                  end
         | 
| 23 23 |  | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 24 | 
            +
                  def self.check_payment_status(token, payment_id)
         | 
| 25 | 
            +
                    API.new(token).get_request("payments/#{payment_id}")
         | 
| 26 | 
            +
                  end
         | 
| 27 27 |  | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 28 | 
            +
                  def self.requires_redirect_param?
         | 
| 29 | 
            +
                    false
         | 
| 30 | 
            +
                  end
         | 
| 31 31 |  | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
                        def initialize(order, account, options = {})
         | 
| 36 | 
            -
                          @token = account
         | 
| 37 | 
            -
                          @redirect_parameters = {
         | 
| 38 | 
            -
                            :amount => options[:amount],
         | 
| 39 | 
            -
                            :description => options[:description],
         | 
| 40 | 
            -
                            :redirectUrl => options[:return_url],
         | 
| 41 | 
            -
                            :method => 'mistercash',
         | 
| 42 | 
            -
                            :metadata => { :order => order }
         | 
| 43 | 
            -
                          }
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                          @redirect_parameters[:webhookUrl] = options[:notify_url] if options[:notify_url]
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                          super
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                          raise ArgumentError, "The return_url option needs to be set." if options[:return_url].blank?
         | 
| 50 | 
            -
                          raise ArgumentError, "The description option needs to be set." if options[:description].blank?
         | 
| 51 | 
            -
                        end
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                        def credential_based_url
         | 
| 54 | 
            -
                          response = request_redirect
         | 
| 55 | 
            -
                          uri = URI.parse(response['links']['paymentUrl'])
         | 
| 56 | 
            -
                          uri.to_s
         | 
| 57 | 
            -
                        end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                        def form_method
         | 
| 60 | 
            -
                          "GET"
         | 
| 61 | 
            -
                        end
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                        def request_redirect
         | 
| 64 | 
            -
                          MollieMistercash.create_payment(token, redirect_parameters)
         | 
| 65 | 
            -
                        rescue ActiveUtils::ResponseError => e
         | 
| 66 | 
            -
                          case e.response.code
         | 
| 67 | 
            -
                          when '401', '403', '422'
         | 
| 68 | 
            -
                            error = JSON.parse(e.response.body)['error']['message']
         | 
| 69 | 
            -
                            raise ActionViewHelperError, error
         | 
| 70 | 
            -
                          when '503'
         | 
| 71 | 
            -
                            raise ActionViewHelperError, 'Service temporarily unavailable. Please try again.'
         | 
| 72 | 
            -
                          else
         | 
| 73 | 
            -
                            raise
         | 
| 74 | 
            -
                          end
         | 
| 75 | 
            -
                        end
         | 
| 32 | 
            +
                  class Helper < Mollie::Helper
         | 
| 33 | 
            +
                    attr_reader :transaction_id, :redirect_parameters, :token
         | 
| 76 34 |  | 
| 77 | 
            -
                     | 
| 35 | 
            +
                    def initialize(order, account, options = {})
         | 
| 36 | 
            +
                      @token = account
         | 
| 37 | 
            +
                      @redirect_parameters = {
         | 
| 38 | 
            +
                        :amount => options[:amount],
         | 
| 39 | 
            +
                        :description => options[:description],
         | 
| 40 | 
            +
                        :redirectUrl => options[:return_url],
         | 
| 41 | 
            +
                        :method => 'mistercash',
         | 
| 42 | 
            +
                        :metadata => { :order => order }
         | 
| 43 | 
            +
                      }
         | 
| 78 44 |  | 
| 79 | 
            -
             | 
| 80 | 
            -
                      def initialize(post_arguments, options = {})
         | 
| 81 | 
            -
                        super
         | 
| 45 | 
            +
                      @redirect_parameters[:webhookUrl] = options[:notify_url] if options[:notify_url]
         | 
| 82 46 |  | 
| 83 | 
            -
             | 
| 84 | 
            -
                        raise ArgumentError, "The credential1 option needs to be set to the Mollie API key." if api_key.blank?
         | 
| 85 | 
            -
                      end
         | 
| 47 | 
            +
                      super
         | 
| 86 48 |  | 
| 87 | 
            -
                       | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 49 | 
            +
                      raise ArgumentError, "The return_url option needs to be set." if options[:return_url].blank?
         | 
| 50 | 
            +
                      raise ArgumentError, "The description option needs to be set." if options[:description].blank?
         | 
| 51 | 
            +
                    end
         | 
| 90 52 |  | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 53 | 
            +
                    def request_redirect
         | 
| 54 | 
            +
                      MollieMistercash.create_payment(token, redirect_parameters)
         | 
| 55 | 
            +
                    rescue ActiveUtils::ResponseError => e
         | 
| 56 | 
            +
                      case e.response.code
         | 
| 57 | 
            +
                      when '401', '403', '422'
         | 
| 58 | 
            +
                        error = JSON.parse(e.response.body)['error']['message']
         | 
| 59 | 
            +
                        raise ActionViewHelperError, error
         | 
| 60 | 
            +
                      when '503'
         | 
| 61 | 
            +
                        raise ActionViewHelperError, 'Service temporarily unavailable. Please try again.'
         | 
| 62 | 
            +
                      else
         | 
| 63 | 
            +
                        raise
         | 
| 93 64 | 
             
                      end
         | 
| 65 | 
            +
                    end
         | 
| 94 66 |  | 
| 95 | 
            -
             | 
| 96 | 
            -
                        params['id']
         | 
| 97 | 
            -
                      end
         | 
| 67 | 
            +
                  end
         | 
| 98 68 |  | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
                       | 
| 69 | 
            +
                  class Notification < OffsitePayments::Notification
         | 
| 70 | 
            +
                    def initialize(post_arguments, options = {})
         | 
| 71 | 
            +
                      super
         | 
| 102 72 |  | 
| 103 | 
            -
                       | 
| 104 | 
            -
             | 
| 105 | 
            -
             | 
| 73 | 
            +
                      raise ArgumentError, "The transaction_id needs to be included in the query string." if transaction_id.nil?
         | 
| 74 | 
            +
                      raise ArgumentError, "The credential1 option needs to be set to the Mollie API key." if api_key.blank?
         | 
| 75 | 
            +
                    end
         | 
| 106 76 |  | 
| 107 | 
            -
             | 
| 108 | 
            -
                       | 
| 109 | 
            -
             | 
| 110 | 
            -
                      end
         | 
| 77 | 
            +
                    def complete?
         | 
| 78 | 
            +
                      true
         | 
| 79 | 
            +
                    end
         | 
| 111 80 |  | 
| 112 | 
            -
             | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 81 | 
            +
                    def item_id
         | 
| 82 | 
            +
                      params['metadata']['order']
         | 
| 83 | 
            +
                    end
         | 
| 115 84 |  | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
                          when 'paidout', 'paid';      'Completed'
         | 
| 120 | 
            -
                          else                         'Failed'
         | 
| 121 | 
            -
                        end
         | 
| 122 | 
            -
                      end
         | 
| 85 | 
            +
                    def transaction_id
         | 
| 86 | 
            +
                      params['id']
         | 
| 87 | 
            +
                    end
         | 
| 123 88 |  | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 89 | 
            +
                    def api_key
         | 
| 90 | 
            +
                      @options[:credential1]
         | 
| 91 | 
            +
                    end
         | 
| 127 92 |  | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
                      end
         | 
| 93 | 
            +
                    def currency
         | 
| 94 | 
            +
                      "EUR"
         | 
| 95 | 
            +
                    end
         | 
| 132 96 |  | 
| 133 | 
            -
             | 
| 134 | 
            -
             | 
| 97 | 
            +
                    # the money amount we received in X.2 decimal.
         | 
| 98 | 
            +
                    def gross
         | 
| 99 | 
            +
                      @params['amount']
         | 
| 100 | 
            +
                    end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                    def gross_cents
         | 
| 103 | 
            +
                      (BigDecimal.new(@params['amount'], 2) * 100).to_i
         | 
| 104 | 
            +
                    end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                    def status
         | 
| 107 | 
            +
                      case @params['status']
         | 
| 108 | 
            +
                      when 'open';                 'Pending'
         | 
| 109 | 
            +
                      when 'paidout', 'paid';      'Completed'
         | 
| 110 | 
            +
                      else                         'Failed'
         | 
| 135 111 | 
             
                      end
         | 
| 136 112 | 
             
                    end
         | 
| 137 113 |  | 
| 138 | 
            -
                     | 
| 114 | 
            +
                    def test?
         | 
| 115 | 
            +
                      @params['mode'] == 'test'
         | 
| 116 | 
            +
                    end
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                    def acknowledge(authcode = nil)
         | 
| 119 | 
            +
                      @params = check_payment_status(transaction_id)
         | 
| 120 | 
            +
                      true
         | 
| 121 | 
            +
                    end
         | 
| 122 | 
            +
             | 
| 123 | 
            +
                    def check_payment_status(transaction_id)
         | 
| 124 | 
            +
                      MollieMistercash.check_payment_status(@options[:credential1], transaction_id)
         | 
| 139 125 | 
             
                    end
         | 
| 126 | 
            +
                  end
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                  class Return < OffsitePayments::Return
         | 
| 129 | 
            +
                  end
         | 
| 140 130 |  | 
| 141 131 | 
             
                end
         | 
| 142 132 | 
             
              end
         |