Class: PaygatePk::Providers::PayFast::Checkout

Inherits:
Client
  • Object
show all
Defined in:
lib/paygate_pk/providers/pay_fast/checkout.rb

Overview

Builds and submits a hosted checkout request to PayFast.

Usage:

client   = PaygatePk::Providers::PayFast::Checkout.new(config: PaygatePk.config.payfast)
checkout = client.create!(
  token: token.token,
  basket_id: "B-1001",
  amount: 1500,
  customer: { mobile: "03xxxxxxxxx", email: "[email protected]" },
  success_url: "...",
  failure_url: "...",
  description: "Order #1001",
  checkout_mode: :immediate
)

Constant Summary collapse

ENDPOINT =
"/Ecommerce/api/Transaction/PostTransaction"
REQUIRED_ROOT_KEYS =
i[token basket_id amount success_url failure_url description].freeze
REQUIRED_CUSTOMER_KEYS =
i[mobile email].freeze

Instance Method Summary collapse

Methods inherited from Client

#create_checkout, #get_access_token, #get_bearer_token, #initialize, #instruments, #verify_ipn!

Constructor Details

This class inherits a constructor from PaygatePk::Providers::PayFast::Client

Instance Method Details

#create!(opts: {}) ⇒ PaygatePk::Contracts::HostedCheckout



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/paygate_pk/providers/pay_fast/checkout.rb', line 45

def create!(opts: {})
  validate_config!
  validate_args!(opts)

  form = build_form(opts)

  response = http.post(opts[:endpoint] || ENDPOINT, form: form)

  PaygatePk::Contracts::HostedCheckout.new(
    provider: :payfast,
    basket_id: opts[:basket_id],
    amount: opts[:amount],
    url: PaygatePk::Util::Html.first_anchor_href(response),
    form: PaygatePk::Util::Html.extract_form(response),
    raw: response
  )
end