Sha256: f1d13e7ee95903ba59f82b4e2bbc61dcd5f411b392f5a34547192dd7d04baaa2

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module PayEx::CreditCardRedirect
  extend self

  def initialize_transaction! params
    response = PayEx::PxOrder.Initialize8 \
      orderID: params[:order_id],
      purchaseOperation: 'AUTHORIZATION',
      productNumber: params[:product_number],
      description: params[:product_description],
      price: params[:price],
      clientIPAddress: params[:customer_ip],
      returnUrl: params[:return_url],
      cancelUrl: params[:cancel_url]

    response[:redirect_url]
  end

  def complete_transaction! id
    response = PayEx::PxOrder.Complete(orderRef: id)

    status = response[:transaction_status]
    status = PayEx::API.parse_transaction_status(status)

    case status
    when :authorize
      error = nil
    when :initialize
      error = PayEx::Error.new('Transaction not completed')
    when :failure
      details = response[:error_details].inspect
      case details
      when /declined/i
        error = PayEx::Error::CardDeclined.new('Card declined')
      else
        error = PayEx::Error.new('Transaction failed')
      end
    else
      error = PayEx::Error.new('Transaction failed')
    end

    [response[:order_id], error, response]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
payex-0.4 lib/payex/credit_card_redirect.rb