Class: Preauth

Inherits:
PreauthBase show all
Defined in:
lib/rave_ruby/rave_objects/preauth.rb

Instance Attribute Summary

Attributes inherited from Base

#get_hashed_key, #rave_object

Instance Method Summary collapse

Methods inherited from PreauthBase

#handle_capture_response, #handle_charge_response, #handle_refund_void_response, #handle_verify_response

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

#capture(flwRef, amount = nil) ⇒ Object

method to capture transaction



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rave_ruby/rave_objects/preauth.rb', line 49

def capture(flwRef, amount=nil)
    base_url = rave_object.base_url

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

    payload = payload.to_json

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

#initiate_charge(data) ⇒ Object

method to initiate preauth transaction



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
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rave_ruby/rave_objects/preauth.rb', line 7

def initiate_charge(data)

    base_url = rave_object.base_url
    secret_key = rave_object.secret_key.dup
    hashed_secret_key = get_hashed_key
    public_key = rave_object.public_key

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


    # 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, "charge_type" => "preauth"})

    # only update the payload with the transaction reference if it isn't already added to the payload
    if data.key?("token")
        data.merge!({"SECKEY" => secret_key})
        payload = data.to_json
        response = post_request("#{base_url}#{BASE_ENDPOINTS::PREAUTH_CHARGE_ENDPOINT}", payload) 
        return handle_charge_response(response)
    else
        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
end

#refund(flwRef) ⇒ Object

method to refund a transaction



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rave_ruby/rave_objects/preauth.rb', line 65

def refund(flwRef)
    base_url = rave_object.base_url

    payload = {
        "ref" => flwRef,
        "action" => "refund",
        "SECKEY" => rave_object.secret_key.dup,
    }

    payload = payload.to_json

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

#verify_preauth(txRef) ⇒ Object

method to verify preauth transaction



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rave_ruby/rave_objects/preauth.rb', line 97

def verify_preauth(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

#void(flwRef) ⇒ Object

method to void a transaction



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rave_ruby/rave_objects/preauth.rb', line 81

def void(flwRef)
    base_url = rave_object.base_url

    payload = {
        "ref" => flwRef,
        "action" => "void",
        "SECKEY" => rave_object.secret_key.dup,
    }

    payload = payload.to_json

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