Class: Payzen::PaymentResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/payzen/payment_response.rb

Class Method Summary collapse

Class Method Details

.fractional_payment(params, ext_trans_id, gc_brand, gc_debits, amount, cc_debit, status = 'CAPTURED') ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/payzen/payment_response.rb', line 4

def self.fractional_payment(params, ext_trans_id, gc_brand, gc_debits, amount, cc_debit, status='CAPTURED')
  result = { vads_amount:           amount,
             vads_effective_amount: amount,
             vads_card_brand:       'MULTI',
             vads_payment_seq:      {trans_id: params[:vads_trans_id], transactions: []} }
  gc_debits.each_with_index do |debit, i|
    transaction = {
        amount:              to_cents(debit['amount']),
        operation_type:      'DEBIT',
        capture_delay:       '0',
        card_brand:          gc_brand,
        card_number:         debit['code'],
        payment_certificate: '',
        presentation_date:   params[:vads_trans_date],
        ext_trans_id:        ext_trans_id,
        sequence_number:     i+1,
        trans_id:            params[:vads_trans_id],
        trans_status:        status}
    result[:vads_payment_seq][:transactions].push(transaction)
  end
  if cc_debit
    cc_debit[:sequence_number] = result[:vads_payment_seq][:transactions].size+1
    result[:vads_payment_seq][:transactions].push(cc_debit)
  end
  result[:vads_payment_seq] = result[:vads_payment_seq].to_json
  response = params.merge(result)
  response.reject!{|k, v| k == :vads_card_number || k == :vads_expiry_month || k == :vads_expiry_year || k == :vads_bank_code ||
                   k == :vads_bank_product || k == :vads_card_country}
  response[:signature] = Payzen.signature(response)
  response
end

.response_with_psp(params, ext_trans_id, gc_brand, gc_debits, coupon_amount) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/payzen/payment_response.rb', line 71

def self.response_with_psp(params, ext_trans_id, gc_brand, gc_debits, coupon_amount)
  if gc_debits.nil? || gc_debits.empty?
    return params
  end
  payment_seq = { amount:              params[:vads_amount],
                  operation_type:      params[:vads_operation_type],
                  auth_number:         params[:vads_auth_number],
                  capture_delay:       params[:vads_capture_delay],
                  card_brand:          params[:vads_card_brand],
                  card_number:         params[:vads_card_number],
                  expiry_month:        params[:vads_expiry_month],
                  expiry_year:         params[:vads_expiry_year],
                  payment_certificate: params[:vads_payment_certificate],
                  presentation_date:   params[:vads_trans_date],
                  trans_id:            params[:vads_trans_id],
                  trans_status:        params[:vads_trans_status] }
  fractional_payment(params, ext_trans_id, gc_brand, gc_debits, (params[:vads_amount].to_i + to_cents(coupon_amount)).to_s, payment_seq)
end

.response_without_psp(params, ext_trans_id, gc_brand, gc_debits, status = 'CAPTURED') ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/payzen/payment_response.rb', line 36

def self.response_without_psp(params, ext_trans_id, gc_brand, gc_debits, status='CAPTURED')
  if gc_debits.empty?
    return params
  end
  if (gc_debits.size > 1)
    result = fractional_payment(params, ext_trans_id, gc_brand, gc_debits, params[:vads_amount], nil, status)
  else
    result = { vads_amount:           params[:vads_amount],
               vads_effective_amount: params[:vads_amount],
               vads_presentation_date: params[:vads_trans_date],
               vads_effective_creation_date: params[:vads_trans_date],
               vads_warranty_result: 'NO',
               vads_validation_mode: '0',
               vads_card_brand:       gc_brand,
               vads_card_number: gc_debits[0]['code'],
               vads_trans_status: status,
               vads_capture_delay: '0',
               vads_auth_mode: 'FULL',
               vads_auth_number: '',
               vads_auth_result: '00',
               vads_threeds_enrolled: '',
               vads_threeds_status: '',
               vads_sequence_number: '1',
               vads_ext_trans_id: ext_trans_id,
               vads_operation_type: 'DEBIT',
               vads_payment_certificate: '',
               vads_card_country: 'FR',
               vads_result: '00',
               vads_language: 'fr'}
    result = params.merge(result)
    result[:signature] = Payzen.signature(result)
  end
  result
end