poundpay 0.2.9 → 0.3
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.
- data/.gitignore +3 -0
- data/README.rdoc +50 -3
- data/examples/simple_application/.rvmrc +1 -1
- data/examples/simple_application/application.rb +152 -48
- data/examples/simple_application/config.rb +14 -5
- data/examples/simple_application/config.ru +16 -2
- data/examples/simple_application/index.html.erb +125 -14
- data/examples/simple_application/static/css/simplemp.css +13 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
- data/examples/simple_application/static/css/ui-lightness/jquery-ui-1.8.13.custom.css +578 -0
- data/examples/simple_application/static/favicon.ico +0 -0
- data/examples/simple_application/static/js/jquery-1.6.1.js +8936 -0
- data/examples/simple_application/static/js/jquery-ui-1.8.13.custom.min.js +784 -0
- data/examples/simple_application/static/js/simplemp.js +177 -0
- data/lib/poundpay.rb +2 -1
- data/lib/poundpay/elements.rb +38 -18
- data/lib/poundpay/exceptions.rb +10 -0
- data/lib/poundpay/version.rb +1 -1
- data/spec/fixtures/charge_permissions.rb +24 -0
- data/spec/fixtures/payments.rb +0 -6
- data/spec/poundpay/elements_spec.rb +34 -43
- data/spec/poundpay/exceptions_spec.rb +11 -0
- metadata +29 -21
| @@ -0,0 +1,177 @@ | |
| 1 | 
            +
            function createChargePermission () {
         | 
| 2 | 
            +
              var args = {};
         | 
| 3 | 
            +
              var inputs = $('#chargePermissionTable input').each(function(i, item) {
         | 
| 4 | 
            +
                args[item.id] = item.value;
         | 
| 5 | 
            +
              });
         | 
| 6 | 
            +
              var request = {};
         | 
| 7 | 
            +
              request.url = "charge_permission";
         | 
| 8 | 
            +
              request.type = "POST";
         | 
| 9 | 
            +
              request.data = $.param(args);
         | 
| 10 | 
            +
              request.success = function(data) {
         | 
| 11 | 
            +
                $('#charge_permission_id').val(data);
         | 
| 12 | 
            +
                $('#operating_charge_permission_sid').val(data);
         | 
| 13 | 
            +
              };
         | 
| 14 | 
            +
              $.ajax(request);
         | 
| 15 | 
            +
            }
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            function findChargePermission () {
         | 
| 18 | 
            +
              var args = {};
         | 
| 19 | 
            +
              args.email_address = $('#email_address').val()
         | 
| 20 | 
            +
              var request = {};
         | 
| 21 | 
            +
              request.url = "charge_permission/find";
         | 
| 22 | 
            +
              request.type = "POST";
         | 
| 23 | 
            +
              request.data = $.param(args);
         | 
| 24 | 
            +
              request.success = function(data) {
         | 
| 25 | 
            +
                $('#find_charge_permission_results').html(data);
         | 
| 26 | 
            +
              };
         | 
| 27 | 
            +
              request.error = function() {
         | 
| 28 | 
            +
                $('#find_charge_permission_results').html('');
         | 
| 29 | 
            +
              };
         | 
| 30 | 
            +
              $.ajax(request);
         | 
| 31 | 
            +
            }
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            function deactivateChargePermission () {
         | 
| 34 | 
            +
              var args = {};
         | 
| 35 | 
            +
              args.sid = $('#charge_permission_id').val()
         | 
| 36 | 
            +
              var request = {};
         | 
| 37 | 
            +
              request.url = "charge_permission/deactivate";
         | 
| 38 | 
            +
              request.type = "POST";
         | 
| 39 | 
            +
              request.data = $.param(args);
         | 
| 40 | 
            +
              $.ajax(request);
         | 
| 41 | 
            +
            }
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            function startChargePermissionIFrame() {
         | 
| 44 | 
            +
              // invoke charge permission iframe
         | 
| 45 | 
            +
              var args = {
         | 
| 46 | 
            +
                success: chargePermissionSuccessCallback,
         | 
| 47 | 
            +
                error: chargePermissionErrorCallback,
         | 
| 48 | 
            +
                charge_permission_sid: $('#charge_permission_id').val(),
         | 
| 49 | 
            +
                server: $('#charge_permission_server').val(),
         | 
| 50 | 
            +
                name: $('#charge_permission_cardholder_name').val(),
         | 
| 51 | 
            +
                address_street: '',
         | 
| 52 | 
            +
                address_city: '',
         | 
| 53 | 
            +
                address_state: '',
         | 
| 54 | 
            +
                address_zip: '',
         | 
| 55 | 
            +
                poundroot_id: 'pound-pcp'
         | 
| 56 | 
            +
              };
         | 
| 57 | 
            +
              PoundPay.init(args);
         | 
| 58 | 
            +
            }
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            function chargePermissionSuccessCallback() {
         | 
| 61 | 
            +
              $("#pound-pcp").hide();
         | 
| 62 | 
            +
              $('#chargePermissionComplete').show();
         | 
| 63 | 
            +
            }
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            function chargePermissionErrorCallback() {
         | 
| 66 | 
            +
              $("#pound-pcp").hide();
         | 
| 67 | 
            +
              alert("an error occurred");
         | 
| 68 | 
            +
            }
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            function createPayment () {
         | 
| 71 | 
            +
              var args = {};
         | 
| 72 | 
            +
              var inputs = $('#paymentsTable input').each(function(i, item) {
         | 
| 73 | 
            +
                args[item.id] = item.value;
         | 
| 74 | 
            +
              });
         | 
| 75 | 
            +
              var request = {};
         | 
| 76 | 
            +
              request.url = "payment";
         | 
| 77 | 
            +
              request.type = "POST";
         | 
| 78 | 
            +
              request.data = $.param(args);
         | 
| 79 | 
            +
              request.success = function(data) {
         | 
| 80 | 
            +
                $('#payment_id').val(data);
         | 
| 81 | 
            +
                $('#operating_payment_sid').val(data);
         | 
| 82 | 
            +
              };
         | 
| 83 | 
            +
              $.ajax(request);
         | 
| 84 | 
            +
            }
         | 
| 85 | 
            +
             | 
| 86 | 
            +
            function createUser () {
         | 
| 87 | 
            +
              var args = {};
         | 
| 88 | 
            +
              var inputs = $('#create_user_table input').each(function(i, item) {
         | 
| 89 | 
            +
                args[item.id] = item.value;
         | 
| 90 | 
            +
              });
         | 
| 91 | 
            +
              var request = {};
         | 
| 92 | 
            +
              request.url = "user";
         | 
| 93 | 
            +
              request.type = "POST";
         | 
| 94 | 
            +
              request.data = $.param(args);
         | 
| 95 | 
            +
              request.success = function(data) {
         | 
| 96 | 
            +
                $('#created_user_results').append(data);
         | 
| 97 | 
            +
              };
         | 
| 98 | 
            +
              $.ajax(request);
         | 
| 99 | 
            +
            }
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            function authorizePayment () {
         | 
| 102 | 
            +
              var args = {};
         | 
| 103 | 
            +
              args.sid = $('#operating_payment_sid').val()
         | 
| 104 | 
            +
              var request = {};
         | 
| 105 | 
            +
              request.url = "payment/authorize";
         | 
| 106 | 
            +
              request.type = "POST";
         | 
| 107 | 
            +
              request.data = $.param(args);
         | 
| 108 | 
            +
              request.success = function(data) {
         | 
| 109 | 
            +
                $('#operation_results').append(data);
         | 
| 110 | 
            +
              };
         | 
| 111 | 
            +
              $.ajax(request);
         | 
| 112 | 
            +
            }
         | 
| 113 | 
            +
             | 
| 114 | 
            +
            function escrowPayment () {
         | 
| 115 | 
            +
              var args = {};
         | 
| 116 | 
            +
              args.sid = $('#operating_payment_sid').val()
         | 
| 117 | 
            +
              var request = {};
         | 
| 118 | 
            +
              request.url = "payment/escrow";
         | 
| 119 | 
            +
              request.type = "POST";
         | 
| 120 | 
            +
              request.data = $.param(args);
         | 
| 121 | 
            +
              request.success = function(data) {
         | 
| 122 | 
            +
                $('#operation_results').append(data);
         | 
| 123 | 
            +
              };
         | 
| 124 | 
            +
              $.ajax(request);
         | 
| 125 | 
            +
            }
         | 
| 126 | 
            +
             | 
| 127 | 
            +
            function releasePayment () {
         | 
| 128 | 
            +
              var args = {};
         | 
| 129 | 
            +
              args.sid = $('#operating_payment_sid').val()
         | 
| 130 | 
            +
              var request = {};
         | 
| 131 | 
            +
              request.url = "payment/release";
         | 
| 132 | 
            +
              request.type = "POST";
         | 
| 133 | 
            +
              request.data = $.param(args);
         | 
| 134 | 
            +
              request.success = function(data) {
         | 
| 135 | 
            +
                $('#operation_results').append(data);
         | 
| 136 | 
            +
              };
         | 
| 137 | 
            +
              $.ajax(request);
         | 
| 138 | 
            +
            }
         | 
| 139 | 
            +
             | 
| 140 | 
            +
            function cancelPayment () {
         | 
| 141 | 
            +
              var args = {};
         | 
| 142 | 
            +
              args.sid = $('#operating_payment_sid').val()
         | 
| 143 | 
            +
              var request = {};
         | 
| 144 | 
            +
              request.url = "payment/cancel";
         | 
| 145 | 
            +
              request.type = "POST";
         | 
| 146 | 
            +
              request.data = $.param(args);
         | 
| 147 | 
            +
              request.success = function(data) {
         | 
| 148 | 
            +
                $('#operation_results').append(data);
         | 
| 149 | 
            +
              };
         | 
| 150 | 
            +
              $.ajax(request);
         | 
| 151 | 
            +
            }
         | 
| 152 | 
            +
             | 
| 153 | 
            +
            function startIFrame() {
         | 
| 154 | 
            +
              // invoke Pound iframe
         | 
| 155 | 
            +
              var args = {
         | 
| 156 | 
            +
                success: paymentSuccessCallback,
         | 
| 157 | 
            +
                error: paymentErrorCallback,
         | 
| 158 | 
            +
                payment_sid: $('#payment_id').val(),
         | 
| 159 | 
            +
                server: $('#server').val(),
         | 
| 160 | 
            +
                name: $('#cardholder_name').val(),
         | 
| 161 | 
            +
                address_street: '',
         | 
| 162 | 
            +
                address_city: '',
         | 
| 163 | 
            +
                address_state: '',
         | 
| 164 | 
            +
                address_zip: ''
         | 
| 165 | 
            +
              };
         | 
| 166 | 
            +
              PoundPay.init(args);
         | 
| 167 | 
            +
            }
         | 
| 168 | 
            +
             | 
| 169 | 
            +
            function paymentSuccessCallback() {
         | 
| 170 | 
            +
              $("#pound-root").hide();
         | 
| 171 | 
            +
              $('#paymentComplete').show();
         | 
| 172 | 
            +
            }
         | 
| 173 | 
            +
             | 
| 174 | 
            +
            function paymentErrorCallback() {
         | 
| 175 | 
            +
              $("#pound-root").hide();
         | 
| 176 | 
            +
              alert("an error occurred");
         | 
| 177 | 
            +
            }
         | 
    
        data/lib/poundpay.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            require 'poundpay/resource'
         | 
| 2 2 | 
             
            require 'poundpay/elements'
         | 
| 3 3 | 
             
            require 'poundpay/callback'
         | 
| 4 | 
            +
            require 'poundpay/exceptions'
         | 
| 4 5 | 
             
            require 'poundpay/rails'
         | 
| 5 6 |  | 
| 6 7 |  | 
| @@ -24,7 +25,7 @@ module Poundpay | |
| 24 25 | 
             
                  end
         | 
| 25 26 |  | 
| 26 27 | 
             
                  yield self if block_given?
         | 
| 27 | 
            -
             | 
| 28 | 
            +
             | 
| 28 29 | 
             
                  api_url.sub! /(\/)$/, ""  # Remove trailing backslash
         | 
| 29 30 | 
             
                  www_url.sub /(\/)$/, ""
         | 
| 30 31 | 
             
                  Resource.site = "#{api_url}/#{api_version}/"
         | 
    
        data/lib/poundpay/elements.rb
    CHANGED
    
    | @@ -5,10 +5,10 @@ require 'poundpay/resource' | |
| 5 5 | 
             
            class PaymentException < Exception
         | 
| 6 6 | 
             
            end
         | 
| 7 7 |  | 
| 8 | 
            -
            class  | 
| 8 | 
            +
            class PaymentAuthorizeException < PaymentException
         | 
| 9 9 | 
             
            end
         | 
| 10 10 |  | 
| 11 | 
            -
            class  | 
| 11 | 
            +
            class PaymentEscrowException < PaymentException
         | 
| 12 12 | 
             
            end
         | 
| 13 13 |  | 
| 14 14 | 
             
            class PaymentReleaseException < PaymentException
         | 
| @@ -17,6 +17,12 @@ end | |
| 17 17 | 
             
            class PaymentCancelException < PaymentException
         | 
| 18 18 | 
             
            end
         | 
| 19 19 |  | 
| 20 | 
            +
            class ChargePermissionException < Exception
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            class ChargePermissionDeactivateException < ChargePermissionException
         | 
| 24 | 
            +
            end
         | 
| 25 | 
            +
             | 
| 20 26 | 
             
            module Poundpay
         | 
| 21 27 | 
             
              class Developer < Resource
         | 
| 22 28 | 
             
                def self.me
         | 
| @@ -25,6 +31,7 @@ module Poundpay | |
| 25 31 |  | 
| 26 32 | 
             
                def save
         | 
| 27 33 | 
             
                  validate_url callback_url
         | 
| 34 | 
            +
                  validate_url charge_permission_callback_url
         | 
| 28 35 | 
             
                  super
         | 
| 29 36 | 
             
                end
         | 
| 30 37 |  | 
| @@ -32,6 +39,11 @@ module Poundpay | |
| 32 39 | 
             
                  validate_url url
         | 
| 33 40 | 
             
                  attributes['callback_url'] = url
         | 
| 34 41 | 
             
                end
         | 
| 42 | 
            +
                
         | 
| 43 | 
            +
                def charge_permission_callback_url=(url)
         | 
| 44 | 
            +
                  validate_url url
         | 
| 45 | 
            +
                  attributes['charge_permission_callback_url'] = url
         | 
| 46 | 
            +
                end
         | 
| 35 47 |  | 
| 36 48 | 
             
                protected
         | 
| 37 49 | 
             
                  def validate_url(url)
         | 
| @@ -45,33 +57,40 @@ module Poundpay | |
| 45 57 |  | 
| 46 58 | 
             
              class User < Resource
         | 
| 47 59 | 
             
              end
         | 
| 60 | 
            +
              
         | 
| 61 | 
            +
              class ChargePermission < Resource
         | 
| 62 | 
            +
                def deactivate
         | 
| 63 | 
            +
                  states = ['CREATED', 'ACTIVE']
         | 
| 64 | 
            +
                  unless states.include?(state)
         | 
| 65 | 
            +
                    raise ChargePermissionDeactivateException.new "Charge permission state is #{state}.  Only CREATED or ACTIVE charge permissions may be deactivated."
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
                  attributes['state'] = 'INACTIVE'
         | 
| 68 | 
            +
                  save
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
              end
         | 
| 48 71 |  | 
| 49 72 | 
             
              class Payment < Resource
         | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 73 | 
            +
             | 
| 74 | 
            +
                def authorize
         | 
| 75 | 
            +
                  unless status == 'STAGED'
         | 
| 76 | 
            +
                    raise PaymentAuthorizeException.new "Payment status is #{status}.  Only STAGED payments may be AUTHORIZED."
         | 
| 53 77 | 
             
                  end
         | 
| 54 78 | 
             
                  attributes['status'] = 'ESCROWED'
         | 
| 55 79 | 
             
                  save
         | 
| 56 80 | 
             
                end
         | 
| 57 81 |  | 
| 58 | 
            -
                def  | 
| 59 | 
            -
                   | 
| 60 | 
            -
             | 
| 61 | 
            -
                    raise PaymentPartiallyReleaseException.new "Payment status is #{status}.  Only ESCROWED or PARTIALLY_RELEASED payments may be released"
         | 
| 82 | 
            +
                def escrow
         | 
| 83 | 
            +
                  unless status == 'AUTHORIZED'
         | 
| 84 | 
            +
                    raise PaymentEscrowException.new "Payment status is #{status}.  Only AUTHORIZED payments may be ESCROWED."
         | 
| 62 85 | 
             
                  end
         | 
| 63 | 
            -
                   | 
| 64 | 
            -
                  # Setting the status through the attributes, however, does work.
         | 
| 65 | 
            -
                  attributes['status'] = 'PARTIALLY_RELEASED'
         | 
| 66 | 
            -
                  attributes['amount_to_release'] = amount_to_release
         | 
| 86 | 
            +
                  attributes['status'] = 'ESCROWED'
         | 
| 67 87 | 
             
                  save
         | 
| 68 | 
            -
                  attributes.delete('amount_to_release')
         | 
| 69 88 | 
             
                end
         | 
| 70 89 |  | 
| 71 90 | 
             
                def release
         | 
| 72 | 
            -
                  statuses = ['ESCROWED' | 
| 91 | 
            +
                  statuses = ['ESCROWED']
         | 
| 73 92 | 
             
                  unless statuses.include?(status)
         | 
| 74 | 
            -
                    raise PaymentReleaseException.new "Payment status is #{status}.  Only ESCROWED  | 
| 93 | 
            +
                    raise PaymentReleaseException.new "Payment status is #{status}.  Only ESCROWED payments may be RELEASED."
         | 
| 75 94 | 
             
                  end
         | 
| 76 95 | 
             
                  # Tried setting status with status=, but save still had status == 'ESCROWED'.
         | 
| 77 96 | 
             
                  # Setting the status through the attributes, however, does work.
         | 
| @@ -80,9 +99,10 @@ module Poundpay | |
| 80 99 | 
             
                end
         | 
| 81 100 |  | 
| 82 101 | 
             
                def cancel
         | 
| 83 | 
            -
                  statuses = [' | 
| 102 | 
            +
                  statuses = ['AUTHORIZED', 'ESCROWED']
         | 
| 84 103 | 
             
                  unless statuses.include?(status)
         | 
| 85 | 
            -
                    raise PaymentCancelException.new "Payment status is #{status}.  Only  | 
| 104 | 
            +
                    raise PaymentCancelException.new "Payment status is #{status}.  Only payments with statuses " \
         | 
| 105 | 
            +
                    "#{statuses.join(', ')} may be canceled"
         | 
| 86 106 | 
             
                  end
         | 
| 87 107 |  | 
| 88 108 | 
             
                  attributes['status'] = 'CANCELED'
         | 
| @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            require 'active_resource/exceptions'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # monkey patch the base AR exception class to provide access to the response body in a structured format.
         | 
| 4 | 
            +
            module ActiveResource
         | 
| 5 | 
            +
              class ConnectionError
         | 
| 6 | 
            +
                def data
         | 
| 7 | 
            +
                  @data ||= ActiveSupport::JSON.decode(self.response.body).symbolize_keys rescue {}
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
    
        data/lib/poundpay/version.rb
    CHANGED
    
    
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            module Poundpay
         | 
| 2 | 
            +
              module ChargePermissionFixture
         | 
| 3 | 
            +
                def created_attributes
         | 
| 4 | 
            +
                  {
         | 
| 5 | 
            +
                    "email_address"              => "john@example.com",
         | 
| 6 | 
            +
                    "state"                      => "CREATED",
         | 
| 7 | 
            +
                    "updated_at"                 => "2011-02-11T19:07:05.332356Z",
         | 
| 8 | 
            +
                    "created_at"                 => "2011-02-11T19:07:05.332356Z",
         | 
| 9 | 
            +
                  }
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def active_attributes
         | 
| 13 | 
            +
                  @attributes = created_attributes
         | 
| 14 | 
            +
                  @attributes["state"] = "ACTIVE"
         | 
| 15 | 
            +
                  @attributes
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def inactive_attributes
         | 
| 19 | 
            +
                  @attributes = created_attributes
         | 
| 20 | 
            +
                  @attributes["state"] = "INACTIVE"
         | 
| 21 | 
            +
                  @attributes
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
            end
         | 
    
        data/spec/fixtures/payments.rb
    CHANGED
    
    | @@ -34,12 +34,6 @@ module Poundpay | |
| 34 34 | 
             
                  @attributes
         | 
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| 37 | 
            -
                def partially_released_payment_attributes
         | 
| 38 | 
            -
                  @attributes = staged_payment_attributes
         | 
| 39 | 
            -
                  @attributes["status"] = "PARTIALLY_RELEASED"
         | 
| 40 | 
            -
                  @attributes
         | 
| 41 | 
            -
                end
         | 
| 42 | 
            -
             | 
| 43 37 | 
             
                def released_payment_attributes
         | 
| 44 38 | 
             
                  @attributes = staged_payment_attributes
         | 
| 45 39 | 
             
                  @attributes["status"] = "RELEASED"
         | 
| @@ -2,6 +2,7 @@ require 'poundpay' | |
| 2 2 | 
             
            require 'poundpay/elements'
         | 
| 3 3 | 
             
            require 'fixtures/payments'
         | 
| 4 4 | 
             
            require 'fixtures/developers'
         | 
| 5 | 
            +
            require 'fixtures/charge_permissions'
         | 
| 5 6 |  | 
| 6 7 | 
             
            include Poundpay
         | 
| 7 8 |  | 
| @@ -94,65 +95,55 @@ describe Payment do | |
| 94 95 | 
             
                  @escrowed_payment.release
         | 
| 95 96 | 
             
                  @escrowed_payment.status.should == 'RELEASED'
         | 
| 96 97 | 
             
                end
         | 
| 98 | 
            +
              end  
         | 
| 97 99 |  | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
                  @escrowed_payment.should_receive(:save).and_return(Payment.new partially_released_payment_attributes)
         | 
| 101 | 
            -
             | 
| 102 | 
            -
                  @escrowed_payment.release
         | 
| 103 | 
            -
                  @escrowed_payment.status.should == 'RELEASED'
         | 
| 104 | 
            -
                end
         | 
| 105 | 
            -
              end
         | 
| 106 | 
            -
             | 
| 107 | 
            -
              describe "#partially_release" do
         | 
| 108 | 
            -
                it "should not be able to partially release a STAGED payment" do
         | 
| 100 | 
            +
              describe "#cancel" do
         | 
| 101 | 
            +
                it "should not be able to cancel a STAGED payment" do
         | 
| 109 102 | 
             
                  @staged_payment = Payment.new staged_payment_attributes
         | 
| 110 | 
            -
                  expect {@staged_payment. | 
| 103 | 
            +
                  expect {@staged_payment.cancel}.to raise_error(PaymentCancelException)
         | 
| 111 104 | 
             
                end
         | 
| 112 105 |  | 
| 113 | 
            -
                it "should  | 
| 106 | 
            +
                it "should cancel an ESCROWED payment" do
         | 
| 114 107 | 
             
                  @escrowed_payment = Payment.new escrowed_payment_attributes
         | 
| 115 | 
            -
                  @escrowed_payment.should_receive(:save).and_return(Payment.new  | 
| 108 | 
            +
                  @escrowed_payment.should_receive(:save).and_return(Payment.new canceled_payment_attributes)
         | 
| 116 109 |  | 
| 117 | 
            -
                  @escrowed_payment. | 
| 118 | 
            -
                  @escrowed_payment.status.should == ' | 
| 110 | 
            +
                  @escrowed_payment.cancel
         | 
| 111 | 
            +
                  @escrowed_payment.status.should == 'CANCELED'
         | 
| 119 112 | 
             
                end
         | 
| 113 | 
            +
              end
         | 
| 114 | 
            +
            end
         | 
| 120 115 |  | 
| 121 | 
            -
             | 
| 122 | 
            -
             | 
| 123 | 
            -
                  @escrowed_payment.should_receive(:save).and_return(Payment.new partially_released_payment_attributes)
         | 
| 116 | 
            +
            describe ChargePermission do
         | 
| 117 | 
            +
              include ChargePermissionFixture
         | 
| 124 118 |  | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 119 | 
            +
              before (:all) do
         | 
| 120 | 
            +
                Poundpay.configure(
         | 
| 121 | 
            +
                  "DV0383d447360511e0bbac00264a09ff3c",
         | 
| 122 | 
            +
                  "c31155b9f944d7aed204bdb2a253fef13b4fdcc6ae1540200449cc4526b2381a")
         | 
| 123 | 
            +
              end
         | 
| 128 124 |  | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
                  expect {@staged_payment.partially_release(123)}.to raise_error(PaymentPartiallyReleaseException)
         | 
| 132 | 
            -
                end
         | 
| 125 | 
            +
              after (:all) do
         | 
| 126 | 
            +
                Poundpay.clear_config!
         | 
| 133 127 | 
             
              end
         | 
| 134 | 
            -
              
         | 
| 135 128 |  | 
| 136 | 
            -
              describe "# | 
| 137 | 
            -
                it "should not be able to  | 
| 138 | 
            -
                  @ | 
| 139 | 
            -
                  expect {@ | 
| 129 | 
            +
              describe "#deactivate" do
         | 
| 130 | 
            +
                it "should not be able to deactivate an INACTIVE charge permission" do
         | 
| 131 | 
            +
                  @inactive_charge_permission = ChargePermission.new inactive_attributes
         | 
| 132 | 
            +
                  expect {@inactive_charge_permission.deactivate}.to raise_error(ChargePermissionDeactivateException)
         | 
| 140 133 | 
             
                end
         | 
| 141 134 |  | 
| 142 | 
            -
                it "should  | 
| 143 | 
            -
                  @ | 
| 144 | 
            -
                  @ | 
| 145 | 
            -
             | 
| 146 | 
            -
                  @ | 
| 147 | 
            -
                  @escrowed_payment.status.should == 'CANCELED'
         | 
| 135 | 
            +
                it "should deactivate a CREATED charge permission" do
         | 
| 136 | 
            +
                  @created_charge_permission = ChargePermission.new created_attributes
         | 
| 137 | 
            +
                  @created_charge_permission.should_receive(:save).and_return(ChargePermission.new created_attributes)
         | 
| 138 | 
            +
                  @created_charge_permission.deactivate
         | 
| 139 | 
            +
                  @created_charge_permission.state.should == 'INACTIVE'
         | 
| 148 140 | 
             
                end
         | 
| 149 141 |  | 
| 150 | 
            -
                it "should  | 
| 151 | 
            -
                  @ | 
| 152 | 
            -
                  @ | 
| 153 | 
            -
             | 
| 154 | 
            -
                  @ | 
| 155 | 
            -
                  @escrowed_payment.status.should == 'CANCELED'
         | 
| 142 | 
            +
                it "should deactivate an ACTIVE charge permission" do
         | 
| 143 | 
            +
                  @active_charge_permission = ChargePermission.new active_attributes
         | 
| 144 | 
            +
                  @active_charge_permission.should_receive(:save).and_return(ChargePermission.new active_attributes)
         | 
| 145 | 
            +
                  @active_charge_permission.deactivate
         | 
| 146 | 
            +
                  @active_charge_permission.state.should == 'INACTIVE'
         | 
| 156 147 | 
             
                end
         | 
| 157 148 | 
             
              end
         | 
| 158 149 | 
             
            end
         |