Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
19 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.2 | ||
0.0.3 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,59 @@ | ||
require 'net/http' | ||
require 'net/https' | ||
require 'json' | ||
require 'config' | ||
require 'pay_response' | ||
require 'abstract_request' | ||
|
||
module PaypalAdaptive | ||
class NoDataError < Exception | ||
end | ||
|
||
class PayRequest | ||
attr_accessor :pay_key | ||
attr_accessor :errors | ||
attr_accessor :env | ||
|
||
def initialize(env = nil) | ||
@env = env | ||
@@config ||= PaypalAdaptive::Config.new(@env) | ||
@@api_base_url ||= @@config.api_base_url | ||
@@headers ||= @@config.headers | ||
end | ||
class PaypalRequest < PaypalAdaptive::AbstractRequest | ||
|
||
def validate | ||
#TODO the receiverList field not validating properly | ||
|
||
# @@schema_filepath = "../lib/pay_request_schema.json" | ||
# @@schema = File.open(@@schema_filepath, "rb"){|f| JSON.parse(f.read)} | ||
# see page 42 of PP Adaptive Payments PDF for explanation of all fields. | ||
#JSON::Schema.validate(@data, @@schema) | ||
end | ||
|
||
def pay(data) | ||
raise NoDataError unless data | ||
|
||
call_api(data, "/AdaptivePayments/Pay") | ||
|
||
response_data = call_api(data, "/AdaptivePayments/Pay") | ||
PaypalAdaptive::PayResponse.new(response_data, @env) | ||
end | ||
|
||
def payment_details(data) | ||
raise NoDataError unless data | ||
|
||
call_api(data, "/AdaptivePayments/PaymentDetails") | ||
end | ||
|
||
def preapproval(data) | ||
raise NoDataError unless data | ||
|
||
call_api(data, "/AdaptivePayments/Preapproval") | ||
end | ||
|
||
def preapproval_details(data) | ||
raise NoDataError unless data | ||
|
||
call_api(data, "/AdaptivePayments/PreapprovalDetails") | ||
end | ||
|
||
def cancel_preapproval(data) | ||
raise NoDataError unless data | ||
|
||
call_api(data, "/AdaptivePayments/CancelPreapproval") | ||
end | ||
|
||
def convert_currency(data) | ||
raise NoDataError unless data | ||
|
||
call_api(data, "/AdaptivePayments/ConvertCurrency") | ||
end | ||
|
||
def refund(data) | ||
raise NoDataError unless data | ||
|
||
call_api(data, "/AdaptivePayments/Refund") | ||
end | ||
|
||
def call_api(data, path) | ||
#hack fix: JSON.unparse doesn't work in Rails 2.3.5; only {}.to_json does.. | ||
api_request_data = JSON.unparse(data) rescue data.to_json | ||
url = URI.parse @@api_base_url | ||
http = Net::HTTP.new(url.host, 443) | ||
http.use_ssl = (url.scheme == 'https') | ||
|
||
resp, response_data = http.post(path, api_request_data, @@headers) | ||
pp_response = PaypalAdaptive::PayResponse.new(response_data, @env) | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains 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
Empty file.