Class: Card

Inherits:
ChargeBase show all
Defined in:
lib/rave_ruby/rave_objects/card.rb

Instance Attribute Summary

Attributes inherited from Base

#get_hashed_key, #rave_object

Instance Method Summary collapse

Methods inherited from ChargeBase

#get_auth_type, #handle_charge_response, #handle_validate_account_response, #handle_validate_response, #handle_verify_account_response, #handle_verify_response, #update_payload

Methods inherited from Base

#check_passed_parameters, #get_request, #handle_list_bank, #initialize, #post_request

Constructor Details

This class inherits a constructor from Base

Instance Method Details

#initiate_charge(data) ⇒ Object

method to initiate card charge



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
35
# File 'lib/rave_ruby/rave_objects/card.rb', line 7

def initiate_charge(data)
    base_url = rave_object.base_url
    hashed_secret_key = get_hashed_key
    public_key = rave_object.public_key
    
    # only update the payload with the transaction reference if it isn't already added to the payload
    if !data.key?("txRef")
        data.merge!({"txRef" => Util.transaction_reference_generator})
    end

    data.merge!({"PBFPubKey" => public_key})

    required_parameters = ["PBFPubKey", "cardno", "cvv", "expirymonth", "expiryyear", "amount", "txRef", "email"]
    check_passed_parameters(required_parameters, data)

    encrypt_data = Util.encrypt(hashed_secret_key, data)

    payload = {
        "PBFPubKey" => public_key,
        "client" => encrypt_data,
        "alg" => "3DES-24"
    }

    payload = payload.to_json

    response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}", payload) 

    return handle_charge_response(response)
end

#tokenized_charge(data) ⇒ Object

method to initiate card charge



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rave_ruby/rave_objects/card.rb', line 38

def tokenized_charge(data)
    base_url = rave_object.base_url
    hashed_secret_key = get_hashed_key
    public_key = rave_object.public_key
    
    # only update the payload with the transaction reference if it isn't already added to the payload
    if !data.key?("txRef")
        data.merge!({"txRef" => Util.transaction_reference_generator})
    end

    data.merge!({"SECKEY" => rave_object.secret_key.dup})

    required_parameters = ["SECKEY", "amount", "currency", "country", "token", "txRef", "email"]
    check_passed_parameters(required_parameters, data)

    payload = data.to_json

    response = post_request("#{base_url}#{BASE_ENDPOINTS::TOKENISED_CHARGE_ENDPOINT}", payload) 

    return handle_charge_response(response)
end

#validate_charge(flwRef, otp) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rave_ruby/rave_objects/card.rb', line 60

def validate_charge(flwRef, otp)
    base_url = rave_object.base_url
    public_key = rave_object.public_key
    
    
    payload = {
        "PBFPubKey" => public_key,
        "transactionreference" => flwRef,
        "transaction_reference" => flwRef,
        "otp" => otp,
    }

    payload = payload.to_json

    response = post_request("#{base_url}#{BASE_ENDPOINTS::CARD_VALIDATE_ENDPOINT}", payload)
    return handle_validate_response(response)
end

#verify_charge(txref) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rave_ruby/rave_objects/card.rb', line 78

def verify_charge(txref)
    base_url = rave_object.base_url

    payload = {
        "txref" => txref,
        "SECKEY" => rave_object.secret_key.dup,
    }

    payload = payload.to_json

    response = post_request("#{base_url}#{BASE_ENDPOINTS::VERIFY_ENDPOINT}", payload)
    return handle_verify_response(response)
end