将3D Secure集成到Spree付款网关中

时间:2018-10-18 15:13:17

标签: ruby-on-rails ruby spree

我正在尝试为我的狂欢商店创建一个新的支付网关。我正在使用https://payfull.com API接受付款。到目前为止,我添加了一个新模型来表示我的付款方式。

class Spree::Gateway::Payfull< Spree::Gateway
  preference :apiKey, :string
  preference :apiSecret, :string


  def auto_capture?
      true
  end
  def provider_class
    Spree::Gateway::Payfull
  end
  def payment_source_class
    Spree::CreditCard
  end

  def method_type
    'payfull'
  end

  def purchase(amount, transaction_details, options = {})
    api_url = 'https://demo13.payfull.com/integration/api/v1';
    merchantPassword = 'PASSWORD';
    params = {
    'merchant' => 'MERCHANTNAME',
    'type' => 'Sale',
    'total' => '1.01',
    'cc_name' => 'Mohammad',
    'cc_number' => '5259222233334444',
    'cc_month' => '12',
    'cc_year' => '2030',
    'cc_cvc' => '000',
    'currency' => 'TRY',
    'installments' => '1',
    'language' => 'tr',
    'client_ip' => '192.168.1.1',
    'payment_title' => 'test payment title',
    'use3d' => '1',
    'return_url' => 'https://your_Application/return3D',
    'customer_firstname' => 'ALI',
    'customer_lastname' => 'MUHAMAD',
    'customer_email' => 'alitestemail@gmail.com',
    'customer_phone' => '5394659832',
    'dealerCode'  => '1722',
    'Username'  => 'PayfullTest',
    'Password'  => 'payfullpasa',
        }


    hashString = ""
    params.sort.each do |key, value|
      length = value.length 
      if length >0
        hashString+= "#{length}" +value
      end
    end
    digest = OpenSSL::Digest.new('sha1')
    hash = OpenSSL::HMAC.hexdigest(digest, merchantPassword, hashString)
    params['hash']= hash
    res = RestClient.post api_url,params
    puts res.body
    ActiveMerchant::Billing::Response.new(true, 'success', {}, {})
  end


end

如果我将use3d设置为0,这几乎可以正常工作,并且给我正确的响应。但是我需要使用3d安全。当我将use3d设置为1时,api调用将以3dsecure确认页面响应我,我必须以某种方式将其显示给用户并读取发布到return_url的数据。我知道我必须通过控制器将API调用中的res.body发送到视图,但不知道该怎么做。感谢您的帮助和提示。

0 个答案:

没有答案