Skip to content

Commit

Permalink
add customer delete
Browse files Browse the repository at this point in the history
  • Loading branch information
mingliangfeng committed Aug 12, 2015
1 parent bd99174 commit 70322dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/pin_payment/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def self.put uri, options = {}
def self.get uri, options = {}
fetch Net::HTTP::Get, uri, options
end

def self.delete uri, options = {}
fetch Net::HTTP::Delete, uri, options
end

def self.fetch klass, uri, options
client = Net::HTTP.new(uri.host, uri.port)
Expand Down
4 changes: 4 additions & 0 deletions lib/pin_payment/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def self.create email, card_or_token = nil
response = post(URI.parse(PinPayment.api_url).tap{|uri| uri.path = '/1/customers' }, options)
new(response.delete('token'), response)
end

def self.delete_customer(token)
delete(URI.parse(PinPayment.api_url).tap{|uri| uri.path = "/1/customers/#{token}" })
end

# Update a customer using the pin API.
#
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/responses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ customer:
created: '{"response":{"token":"cus__03Cn1lSk3offZ0IGkwpCg","email":"[email protected]","created_at":"2013-06-12T10:08:30Z","card":{"token":"card_qMwnMfpG-olOhfJeyxmrcg","display_number":"XXXX-XXXX-XXXX-0000","scheme":"master","address_line1":"123 Main St","address_line2":"","address_city":"Melbourne","address_postcode":"3000","address_state":"Victoria","address_country":"Australia"}}}'
all: '{"response":[{"token":"cus_OEHdj9KE_OiC9eig0h3IEA","email":"[email protected]","created_at":"2013-06-25T04:14:35Z","card":{"token":"card_7rviJ2IZM__WC9Dnj0RHJA","display_number":"XXXX-XXXX-XXXX-0000","scheme":"visa","address_line1":"123 Main St","address_line2":"","address_city":"Melbourne","address_postcode":"3000","address_state":"Victoria","address_country":"Australia"}},{"token":"cus_cO2VtF4YzK6i1QBcLsdzOA","email":"[email protected]","created_at":"2013-06-24T05:53:42Z","card":{"token":"card_bVou2J4hzbDIwe-sQ3ZqdQ","display_number":"XXXX-XXXX-XXXX-0000","scheme":"visa","address_line1":"123 Main St","address_line2":"","address_city":"Melbourne","address_postcode":"3000","address_state":"Victoria","address_country":"Australia"}}],"count":2,"pagination":{"current":1,"previous":null,"next":null,"per_page":25,"pages":1,"count":2}}'
create_with_card: '{"response":{"token":"cus_XZg1ULpWaROQCOT5PdwLkQ","email":"[email protected]","created_at":"2013-06-27T00:24:43Z","card":{"token":"card_nytGw7koRg23EEp9NTmz9w","display_number":"XXXX-XXXX-XXXX-0000","scheme":"master","address_line1":"42 Sevenoaks St","address_line2":null,"address_city":"Lathlain","address_postcode":"6454","address_state":"WA","address_country":"Australia"}}}'
deleted: '{"response":{}}'
delete_not_found: '{"error":"resource_not_found","error_description":"No resource was found at this URL."}'
refund:
success: '{"response":{"token":"rf_wMYx5YHKaZAwQgj5rtNuTg","success":null,"amount":1000,"currency":"USD","charge":"ch_BjGW-S6WUisI6mOgpDRimg","created_at":"2013-06-25T03:16:33Z","error_message":null,"status_message":"Pending"}}'
duplicate: '{"error":"invalid_resource","error_description":"One or more parameters were missing or invalid.","messages":{"charge":["You have tried to refund more than the original charge"]}}'
Expand Down
15 changes: 15 additions & 0 deletions test/test_pin_customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ def test_create_success
customer = created_customer
assert_kind_of PinPayment::Customer, customer
end

def test_delete_success
customer = created_customer
FakeWeb.register_uri(:delete, "https://test-api.pin.net.au/1/customers/#{customer.token}", body: fixtures['responses']['customer']['deleted'])
response = PinPayment::Customer.delete_customer(customer.token)
assert_empty response
end

def test_delete_not_found
token = 'none-existing-token'
FakeWeb.register_uri(:delete, "https://test-api.pin.net.au/1/customers/#{token}", body: fixtures['responses']['customer']['delete_not_found'])
assert_raises PinPayment::Error::ResourceNotFound do
PinPayment::Customer.delete_customer(token)
end
end

def test_direct_update
customer = created_customer
Expand Down

0 comments on commit 70322dc

Please sign in to comment.