title: PayPal error: This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow
body: <p>I was trying to implement paypal payment gateway. </p>
  
  <p>But I am getting an error:</p>
  
  <pre><code>This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow.
  </code></pre>
  
  <p><strong>In Gem File</strong> </p>
  
  <pre><code>gem 'activemerchant', :require =&gt; 'active_merchant'
  </code></pre>
  
  <p><strong>In development.rb</strong></p>
  
  <pre><code> config.after_initialize do
      ActiveMerchant::Billing::Base.mode = :test
      paypal_options = {
        :login =&gt; "************",
        :password =&gt; "************",
        :signature =&gt; "************",
      }
      ::STANDARD_GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(paypal_options)
      ::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
    end
  </code></pre>
  
  <p><strong>Sample code I am using in my controller</strong></p>
  
  <pre><code>  response = EXPRESS_GATEWAY.setup_purchase(10000,
      :ip                =&gt; request.remote_ip,
      :return_url        =&gt; new_order_url,
      :cancel_return_url =&gt; orders_url
    )
    p response
    p response.token
    redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
  </code></pre>
  
  <p>O/p for response:</p>
  
  <pre><code>#&lt;ActiveMerchant::Billing::PaypalExpressResponse:0x007f90bbababa0 @params={"timestamp"=&gt;"2011-12-17T21:41:21Z", "ack"=&gt;"Failure", "correlation_id"=&gt;"c152e1862f475", "version"=&gt;"62.0", "build"=&gt;"2271164", "message"=&gt;"Security header is not valid", "error_codes"=&gt;"10002", "Timestamp"=&gt;"2011-12-17T21:41:21Z", "Ack"=&gt;"Failure", "CorrelationID"=&gt;"c152e1862f475", "Errors"=&gt;{"ShortMessage"=&gt;"Security error", "LongMessage"=&gt;"Security header is not valid", "ErrorCode"=&gt;"10002", "SeverityCode"=&gt;"Error"}, "Version"=&gt;"62.0", "Build"=&gt;"2271164"}, @message="Security header is not valid", @success=false, @test=true, @authorization=nil, @fraud_review=false, @avs_result={"code"=&gt;nil, "message"=&gt;nil, "street_match"=&gt;nil, "postal_match"=&gt;nil}, @cvv_result={"code"=&gt;nil, "message"=&gt;nil}&gt;
  </code></pre>
  
  <p>o/p for response.token</p>
  
  <pre><code>  nil
  </code></pre>
  
  <p>So I think the problem is response.token is nil</p>
  
  <p>any suggestions why this is happening?</p>