Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/cloud_payments/models/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Transaction < Model
property :status_code
property :reason
property :reason_code
property :refunded
property :card_holder_message
property :token

Expand Down Expand Up @@ -80,5 +81,9 @@ def cancelled?
def declined?
status == DECLINED
end

def refunded?
refunded
end
end
end
20 changes: 20 additions & 0 deletions spec/cloud_payments/models/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
status_code: 3,
reason: 'Approved',
reason_code: 0,
refunded: false,
card_holder_message: 'Payment successful',
name: 'CARDHOLDER NAME',
token: 'a4e67841-abb0-42de-a364-d1d8f9f4b3c0'
Expand Down Expand Up @@ -80,6 +81,7 @@
specify{ expect(subject.card_holder_message).to eq('Payment successful') }
specify{ expect(subject.name).to eq('CARDHOLDER NAME') }
specify{ expect(subject.token).to eq('a4e67841-abb0-42de-a364-d1d8f9f4b3c0') }
specify{ expect(subject.refunded).to eq(false) }

context 'without any attributes' do
let(:attributes){ {} }
Expand Down Expand Up @@ -117,6 +119,7 @@
it_behaves_like :not_raise_without_attribute, :issuer_bank_country
it_behaves_like :not_raise_without_attribute, :reason
it_behaves_like :not_raise_without_attribute, :reason_code
it_behaves_like :not_raise_without_attribute, :refunded
it_behaves_like :not_raise_without_attribute, :card_holder_message
it_behaves_like :not_raise_without_attribute, :name
it_behaves_like :not_raise_without_attribute, :token
Expand Down Expand Up @@ -254,5 +257,22 @@
specify{ expect(subject.ip_location).to be_nil }
end
end

describe '#refunded?' do
context do
let(:attributes) { { refunded: false } }
specify { expect(subject.refunded?).to be_falsey }
end

context do
let(:attributes) { { refunded: true } }
specify { expect(subject.refunded?).to be_truthy }
end

context do
let(:attributes) { { refunded: nil } }
specify { expect(subject.refunded?).to be_falsey }
end
end
end
end
6 changes: 6 additions & 0 deletions spec/cloud_payments/namespaces/payments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
specify{ expect(subject.get(transaction_id).id).to eq(transaction_id) }
specify{ expect(subject.get(transaction_id).reason).to eq('Approved') }
end

context 'transaction is refunded' do
before{ stub_api_request('payments/get/refunded').perform }
specify{ expect(subject.get(transaction_id)).to be_completed }
specify{ expect(subject.get(transaction_id)).to be_refunded }
end
end

context 'config.raise_banking_errors = true' do
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/apis/payments/get/failed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"StatusCode": 5,
"Reason": "InsufficientFunds",
"ReasonCode": 5051,
"Refunded": false,
"CardHolderMessage": "Insufficient funds on account",
"Name": "CARDHOLDER NAME"
},
Expand Down
49 changes: 49 additions & 0 deletions spec/fixtures/apis/payments/get/refunded.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
:request:
:url: '/payments/get'
:body: '{"TransactionId":12345}'
:response:
:body: >
{
"Model":{
"TransactionId":12345,
"Amount":10.0,
"Currency":"RUB",
"CurrencyCode":0,
"InvoiceId":"1234567",
"AccountId":"user_x",
"Email":null,
"Description":"Payment for goods on example.com",
"JsonData":null,
"CreatedDate":"\/Date(1401718880000)\/",
"CreatedDateIso":"2014-08-09T11:49:41",
"AuthDate":"\/Date(1401733880523)\/",
"AuthDateIso":"2014-08-09T11:49:42",
"ConfirmDate":"\/Date(1401733880523)\/",
"ConfirmDateIso":"2014-08-09T11:49:42",
"AuthCode":"123456",
"TestMode":true,
"IpAddress":"195.91.194.13",
"IpCountry":"RU",
"IpCity":"Ufa",
"IpRegion":"Bashkortostan Republic",
"IpDistrict":"Volga Federal District",
"IpLatitude":54.7355,
"IpLongitude":55.991982,
"CardFirstSix":"411111",
"CardLastFour":"1111",
"CardType":"Visa",
"CardTypeCode":0,
"IssuerBankCountry":"RU",
"Status":"Completed",
"StatusCode":3,
"Reason":"Approved",
"ReasonCode":0,
"Refunded": true,
"CardHolderMessage":"Payment successful",
"Name":"CARDHOLDER NAME",
"Token":"a4e67841-abb0-42de-a364-d1d8f9f4b3c0"
},
"Success":true,
"Message": null
}
1 change: 1 addition & 0 deletions spec/fixtures/apis/payments/get/successful.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"StatusCode":3,
"Reason":"Approved",
"ReasonCode":0,
"Refunded": false,
"CardHolderMessage":"Payment successful",
"Name":"CARDHOLDER NAME",
"Token":"a4e67841-abb0-42de-a364-d1d8f9f4b3c0"
Expand Down