Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
v1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
somentelucas committed Apr 1, 2019
1 parent 65f9b68 commit c5e4856
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- [Get (details of a payment)](#get-details-of-a-payment)
- [Refunds](#refunds)
- [Create a payment refund](#create-a-payment-refund)
- [Create a payment partial refund](#create-a-payment-partial-refund)
- [Create an order refund](#create-an-order-refund)
- [Get Refund](#get-refund)
- [List Payment Refunds](#list-payment-refunds)
Expand Down Expand Up @@ -500,6 +501,17 @@ moip.payment.refunds.create('PAY-3GALBSZIUSBE')
})
```

#### Create a payment partial refund
```javascript
moip.payment.refunds.create('PAY-3GALBSZIUSBE', {
amount: 100
}).then((response) => {
console.log(response)
}).catch((err) => {
console.log(err)
})
```

#### Create an order refund
```javascript
moip.order.refunds.create('ORD-4GALBSZIUSBE')
Expand Down
4 changes: 2 additions & 2 deletions dist/resources/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var _authorize = function _authorize(opts, _id, amount) {
return _api2.default.get(opts, null, null, { customUrl: _endpoints2.default.sandbox.v2.authorizePaymentSimulationUrl + '?payment_id=' + _id + '&amount' + amount });
};

var refund = function refund(opts, _id, refund) {
return _api2.default.post(opts, '/payments/' + _id + '/refunds', refund);
var refund = function refund(opts, _id, _refund) {
return _api2.default.post(opts, '/payments/' + _id + '/refunds', _refund);
};

var getRefunds = function getRefunds(opts, _id) {
Expand Down
2 changes: 1 addition & 1 deletion lib/resources/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const preAuthorizationCancel = (opts, _id) => api.post(opts, `/payments/${_id}/v

const _authorize = (opts, _id, amount) => api.get(opts, null, null, {customUrl: `${endpoints.sandbox.v2.authorizePaymentSimulationUrl}?payment_id=${_id}&amount${amount}`})

const refund = (opts, _id) => api.post(opts, `/payments/${_id}/refunds`)
const refund = (opts, _id, refund) => api.post(opts, `/payments/${_id}/refunds`, refund)

const getRefunds = (opts, _id) => api.get(opts, `/payments/${_id}/refunds`)

Expand Down
54 changes: 54 additions & 0 deletions test/refund.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,60 @@ describe('Moip Payment Refunds', () => {
})
})

describe('Moip Partial Payment Refunds', () => {
beforeEach((done) => {
setTimeout(done, 2000)
})

before((done) => {
orderModel.ownId = shortid.generate()
orderModel.customer.ownId = shortid.generate()
done()
})

let orderId

it('Should successfully create an order', (done) => {
moip.order.create(orderModel)
.then(({body}) => {
orderId = body.id
done()
})
.catch(done)
})

it('Should successfully create a payment for an order', (done) => {
moip.payment.create(orderId, paymentModel)
.then(({body}) => {
// Verify and add to schema
body.should.have.property('id')
paymentModel.id = body.id
done()
})
.catch(done)
})

it('Should successfully partially refund the payment', (done) => {
moip.payment.refunds.create(paymentModel.id, {
amount: 100
}).then(({body}) => {
body.should.have.property('id')
body.should.have.property('status')
body.status.should.be.eql('COMPLETED')
done()
})
.catch(done)
})

it('Should successfully get all the payment refunds', (done) => {
moip.payment.refunds.get(paymentModel.id)
.then(() => {
done()
})
.catch(done)
})
})

describe('Moip Order Refunds', () => {
beforeEach((done) => {
setTimeout(done, 2000)
Expand Down

0 comments on commit c5e4856

Please sign in to comment.