Skip to content

Instantly share code, notes, and snippets.

@timm-oh
Last active January 13, 2021 04:52
Show Gist options
  • Select an option

  • Save timm-oh/65ea658accd8e923e90a5ccc99b70411 to your computer and use it in GitHub Desktop.

Select an option

Save timm-oh/65ea658accd8e923e90a5ccc99b70411 to your computer and use it in GitHub Desktop.

Revisions

  1. timm-oh revised this gist Jan 13, 2021. 1 changed file with 15 additions and 8 deletions.
    23 changes: 15 additions & 8 deletions snippet.rb
    Original file line number Diff line number Diff line change
    @@ -5,22 +5,29 @@
    'SiteCode': 'SOME_SITE_CODE', # find this here https://dash.ozow.com/MerchantAdmin/Site
    'CountryCode': 'ZA', # only supports ZA currently
    'CurrencyCode': 'ZAR', # only supports ZAR currently
    'Amount': 1000.00, # this is R1000.00
    'Amount': 1000, # this is R1000, not working well for floats though
    'TransactionReference': 'SOME_TEST', # your internal reference to match against
    'BankReference': "Nice Reference", # the reference that the customer will see on their bank statement
    'Optional1': nil,
    'Optional2': nil,
    'Optional3': nil,
    'Optional4': nil,
    'Optional5': nil,
    'Customer': nil,
    'CancelUrl': 'https://www.example.com/webhooks/ozow/success',
    'ErrorUrl': 'https://www.example.com/webhooks/ozow/error',
    'SuccessUrl': 'https://www.example.com/webhooks/ozow/success',
    'NotifyUrl': 'https://www.example.com/webhooks/ozow/notify' # needs to be an endpoint that accepts a POST request
    "IsTest": true, # pretty self explanatory
    }

    # I used #tap because reasons, you're more than welcome to tweak this
    ozow_params.tap do |params|
    super_secret_key = "SOME_SECRET_KEY" # you'll find this here: https://dash.ozow.com/MerchantAdmin/Merchant/Details (Private Key)
    string = params.values.join('').downcase + super_secret_key
    params[:HashCheck] = Digest::SHA512.hexdigest(string)
    end
    ozow_params = ozow_params.compact_blank
    string = ozow_params.values.join('').downcase + "SOME_SECRET_KEY" # you'll find this here: https://dash.ozow.com/MerchantAdmin/Merchant/Details (Private Key)
    ozow_params[:HashCheck] = Digest::SHA512.hexdigest(string)

    base_url = 'https://pay.ozow.com'
    # response should be a redirect (302) to a url that looks something like this: :uuid/Secure
    response = HTTP.post('https://pay.ozow.com', params: ozow_params)
    response = HTTP.post(base_url, params: ozow_params)

    # https://pay.ozow.com/:uuid/Secure
    payment_url = base_url + response.headers['Location']
  2. timm-oh created this gist Jan 6, 2021.
    28 changes: 28 additions & 0 deletions snippet.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # refer to https://ozow.com/integrations/ for more information

    # Ordering with the params matters, see the link above for more information
    ozow_params = {
    'SiteCode': 'SOME_SITE_CODE', # find this here https://dash.ozow.com/MerchantAdmin/Site
    'CountryCode': 'ZA', # only supports ZA currently
    'CurrencyCode': 'ZAR', # only supports ZAR currently
    'Amount': 1000.00, # this is R1000.00
    'TransactionReference': 'SOME_TEST', # your internal reference to match against
    'BankReference': "Nice Reference", # the reference that the customer will see on their bank statement
    "IsTest": true, # pretty self explanatory
    }

    # I used #tap because reasons, you're more than welcome to tweak this
    ozow_params.tap do |params|
    super_secret_key = "SOME_SECRET_KEY" # you'll find this here: https://dash.ozow.com/MerchantAdmin/Merchant/Details (Private Key)
    string = params.values.join('').downcase + super_secret_key
    params[:HashCheck] = Digest::SHA512.hexdigest(string)
    end

    base_url = 'https://pay.ozow.com'
    # response should be a redirect (302) to a url that looks something like this: :uuid/Secure
    response = HTTP.post('https://pay.ozow.com', params: ozow_params)

    # https://pay.ozow.com/:uuid/Secure
    payment_url = base_url + response.headers['Location']

    # you can either load payment_url into an iframe tag, or redirect to that page. Freedom of choice.