module PX::PxPost

Constants

PASSWORD
URL

PX Post endpoint; used in conjunction with DpsBillingId and the Token billing strategy.

USERNAME
XML

Public Class Methods

build(data) click to toggle source
# File lib/px.rb, line 183
def self.build(data)
  params = {
    uid: USERNAME,
    key: PASSWORD,

    # required parameters
    amount: data.fetch(:amount),

    # required, but with sane defaults.
    currency: data.fetch(:currency, "USD"),
    type: data.fetch(:type, TYPE_PURCHASE),

    # mandatory recommendations even though
    # they're optional in the API.
    txn_id: data.fetch(:txn_id, ""),
    ref: data.fetch(:ref, ""),
    token: data.fetch(:token),

    this: Hache,
  }

  mote(XML, params)
end
parse(xml) click to toggle source
# File lib/px.rb, line 171
def self.parse(xml)
  dict = XmlSimple.xml_in(xml, forcearray: false)

  PX::Util.log(:info, self.name, dict.inspect)

  return unless data = dict["Transaction"]

  if data["success"] == "1" && data["responseText"] == "APPROVED"
    return data
  end
end