Created
March 1, 2011 11:46
-
-
Save dbackeus/849020 to your computer and use it in GitHub Desktop.
Simple helper module to help communicate with payex.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Payex | |
mattr_accessor :account_number | |
mattr_accessor :encryption_key | |
MD5_CHECK_FIELDS = { | |
"pxorder/pxorder.asmx/Initialize7" => [:accountNumber, :purchaseOperation, :price, :priceArgList, :currency, :vat, :orderID, :productNumber, :description, :clientIPAddress, :clientIdentifier, :additionalValues, :externalID, :returnUrl, :view, :agreementRef, :cancelUrl, :clientLanguage], | |
"pxagreement/pxagreement.asmx/CreateAgreement3" => [:accountNumber, :merchantRef, :description, :purchaseOperation, :maxAmount, :notifyUrl, :startDate, :stopDate], | |
"pxagreement/pxagreement.asmx/DeleteAgreement" => [:accountNumber, :agreementRef], | |
"pxorder/pxorder.asmx/Complete" => [:accountNumber, :orderRef], | |
"pxagreement/pxagreement.asmx/AutoPay2" => [:accountNumber, :agreementRef, :price, :productNumber, :description, :orderId, :purchaseOperation], | |
"pxagreement/pxrecurring.asmx/Start" => [:accountNumber, :agreementRef, :startDate, :periodType, :period, :alertPeriod, :price, :productNumber, :orderID, :description, :notifyUrl], | |
"pxagreement/pxrecurring.asmx/Stop" => [:accountNumber, :agreementRef] | |
} | |
def self.configure | |
yield self | |
end | |
# Returns - {"header"=>{"name"=>"Payex Header v1.0", "id"=>"ace619b107d4496694c252bff8935b01", "date"=>"2011-02-23 09:25:53"}, "status"=>{"code"=>"OK", "description"=>"OK", "errorCode"=>"OK", "paramName"=>nil, "thirdPartyError"=>nil}, "agreementRef"=>"0eeab2ab482a47e89dec2ae7f9bccb60"} | |
def self.create_agreement(params) | |
params = { | |
:accountNumber => account_number, | |
:merchantRef => "", | |
:description => "", | |
:purchaseOperation => "SALE", | |
:maxAmount => 1000000_00, | |
:notifyUrl => "", | |
:startDate => "", | |
:stopDate => "" | |
}.merge(params) | |
request_and_parse("pxagreement/pxagreement.asmx/CreateAgreement3", params) | |
end | |
# Returns - {"header"=>{"name"=>"Payex Header v1.0", "id"=>"e61d77f797b0450f83ae65398531ab0c", "date"=>"2011-02-24 10:30:56"}, "status"=>{"code"=>"OK", "description"=>"OK", "errorCode"=>"OK", "paramName"=>nil, "thirdPartyError"=>nil}, "agreementRef"=>"ba6694a151f046be8d7b103cb98c9847"} | |
def self.delete_agreement(params) | |
params = { | |
:accountNumber => account_number, | |
:agreementRef => "" | |
}.merge(params) | |
request_and_parse("pxagreement/pxagreement.asmx/DeleteAgreement", params) | |
end | |
# Returns - {"header"=>{"name"=>"Payex Header v1.0", "id"=>"e98384f749f64695a798a8f4292e698d", "date"=>"2011-02-23 09:27:36"}, "status"=>{"code"=>"OK", "description"=>"OK", "errorCode"=>"OK", "paramName"=>nil, "thirdPartyError"=>nil}, "orderRef"=>"4bd70f887feb49c2bee185253dbf751f", "sessionRef"=>"1383af657c204207a1a2a2fc6d133b66", "redirectUrl"=>"https://test-confined.payex.com/PxOrderCC.aspx?orderRef=4bd70f887feb49c2bee185253dbf751f"} | |
def self.initialize(params) | |
params = { | |
:accountNumber => account_number, | |
:purchaseOperation => "SALE", | |
:price => 0, | |
:priceArgList => "", | |
:currency => "", | |
:vat => 0, | |
:orderID => "", | |
:productNumber => "", | |
:description => "", | |
:clientIPAddress => "", | |
:clientIdentifier => "", | |
:additionalValues => "", | |
:externalID => "", | |
:agreementRef => "", | |
:cancelUrl => "", | |
:clientLanguage => "", | |
:returnUrl => "", | |
:view => "" | |
}.merge(params) | |
request_and_parse("pxorder/pxorder.asmx/Initialize7", params) | |
end | |
# Returns - {"header"=>{"name"=>"Payex Header v1.0", "id"=>"c6c17557375c4ad883ebb9af344c4294", "date"=>"2011-02-23 09:46:14"}, "status"=>{"code"=>"OK", "description"=>"OK", "errorCode"=>"OK", "paramName"=>nil, "thirdPartyError"=>nil}, "transactionStatus"=>"0", "orderStatus"=>"0", "transactionRef"=>"53e861eb44dd47eebdc815af1713a08e", "transactionNumber"=>"40114366", "orderId"=>"4c57f3975412901427000005", "productId"=>"basic-1-month", "paymentMethod"=>"VISA", "amount"=>"9900", "alreadyCompleted"=>"False", "clientAccount"=>"0", "productNumber"=>"basic-1-month", "clientGsmNumber"=>nil, "agreementRef"=>"0eeab2ab482a47e89dec2ae7f9bccb60", "paymentMethodExpireDate"=>"20120401", "BankHash"=>"00000001-4581-0917-9501-000000000000", "AuthenticatedStatus"=>"3DSecure", "AuthenticatedWith"=>"Y", "maskedNumber"=>"45**********9501", "fraudData"=>"false", "pending"=>"false"} | |
def self.complete(params) | |
params = { | |
:accountNumber => account_number, | |
:orderRef => "", | |
}.merge(params) | |
request_and_parse("pxorder/pxorder.asmx/Complete", params) | |
end | |
# Returns - {"header"=>{"name"=>"Payex Header v1.0", "id"=>"e0471df66c614a2e83c8942493f0287b", "date"=>"2011-02-23 09:59:09"}, "status"=>{"code"=>"OK", "description"=>"OK", "errorCode"=>"OK", "paramName"=>nil, "thirdPartyError"=>nil}, "transactionStatus"=>"0", "transactionRef"=>"84a8762b17fd4a499a62f7f14fbe172a", "transactionNumber"=>"40114399", "paymentMethod"=>"VISA"} | |
def self.autopay(params) | |
params = { | |
:accountNumber => account_number, | |
:agreementRef => "", | |
:price => 0, | |
:productNumber => "", | |
:description => "", | |
:orderId => "", | |
:purchaseOperation => "SALE" | |
}.merge(params) | |
request_and_parse("pxagreement/pxagreement.asmx/AutoPay2", params) | |
end | |
private | |
def self.request_and_parse(action, params) | |
hashify!(action, params) | |
query = params.collect do |key, value| | |
value = URI.escape(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) | |
"#{key}=#{value}" | |
end.join("&") | |
response = HTTPI.post("https://test-external.payex.com/#{action}", query) | |
Hash.from_xml(Hash.from_xml(response.raw_body)["string"])["payex"] | |
end | |
def self.hashify!(action, params) | |
string = MD5_CHECK_FIELDS[action].collect do |key| | |
params[key] | |
end.join("") | |
string += encryption_key | |
params[:hash] = Digest::MD5.hexdigest(string) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dependency;
Konfigurera med;
Har lagt in funktioner för att skapa agreement för att lagra kreditkort som man sedan kan göra transaktioner från. Se payex dokumentation för att förstå bättre.