Skip to content

Commit

Permalink
success url added to params (#30)
Browse files Browse the repository at this point in the history
* success url added to params

* fixes by comments
  • Loading branch information
niksavkin committed Oct 18, 2018
1 parent 14dd9e3 commit a611338
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
10 changes: 6 additions & 4 deletions README.md
Expand Up @@ -59,7 +59,8 @@ const publicKey = '2tbp1WQvsgQeziGY9vTLe9vDZNg7tmCymb4Lh6STQokqKrpCC6qrUUKEDZAJ7
const params = {
publicKey,
amount: 200,
billId: '893794793973'
billId: '893794793973',
successUrl: 'https://merchant.com/payment/success?billId=893794793973'
};

const link = qiwiApi.createPaymentForm(params);
Expand All @@ -68,7 +69,7 @@ const link = qiwiApi.createPaymentForm(params);
В результате:

```
https://oplata.qiwi.com/create?publicKey=2tbp1WQvsgQeziGY9vTLe9vDZNg7tmCymb4Lh6STQokqKrpCC6qrUUKEDZAJ7mvFnzr1yTebUiQaBLDnebLMMxL8nc6FF5zfmGQnypdXCbQJqHEJW5RJmKfj8nvgc&amount=200&billId=893794793973
https://oplata.qiwi.com/create?publicKey=2tbp1WQvsgQeziGY9vTLe9vDZNg7tmCymb4Lh6STQokqKrpCC6qrUUKEDZAJ7mvFnzr1yTebUiQaBLDnebLMMxL8nc6FF5zfmGQnypdXCbQJqHEJW5RJmKfj8nvgc&amount=200&billId=893794793973&successUrl=https%3A%2F%2Fmerchant.com%2Fpayment%2Fsuccess%3FbillId%3D893794793973&customFields[apiClient]=node_sdk&customFields[apiClientVersion]=3.1.2
```

### Выставление счета
Expand All @@ -86,7 +87,8 @@ const fields = {
comment: 'test',
expirationDateTime: '2018-03-02T08:44:07',
email: 'example@mail.org',
account : 'client4563'
account : 'client4563',
successUrl: 'http://test.ru/'
};

qiwiRestApi.createBill( billId, fields ).then( data => {
Expand All @@ -111,7 +113,7 @@ qiwiRestApi.createBill( billId, fields ).then( data => {
"comment": "test",
"creationDateTime": "2018-07-12T10:28:38.855+03:00",
"expirationDateTime": "2018-08-26T10:28:38.855+03:00",
"payUrl": "https://oplata.qiwi.com/form/?invoice_uid=bb773791-9bd9-42c1-b8fc-3358cd108422"
"payUrl": "https://oplata.qiwi.com/form/?invoice_uid=bb773791-9bd9-42c1-b8fc-3358cd108422&successUrl=http%3A%2F%2Ftest.ru%2F"
}
```

Expand Down
10 changes: 8 additions & 2 deletions lib/QiwiBillPaymentsAPI.js
Expand Up @@ -162,6 +162,7 @@ module.exports = class QiwiBillPaymentsAPI {
* @param {(string|number)} params.billId The bill identifier
* @param {string} params.publicKey The publicKey
* @param {(string|number)} params.amount The amount
* @param {string} params.successUrl The success url
* @return {Promise<Object>|Error} Return Promise with result
*/
createPaymentForm (params) {
Expand Down Expand Up @@ -191,9 +192,10 @@ module.exports = class QiwiBillPaymentsAPI {
* @param {string} params.phone The phone
* @param {string} params.email The email
* @param {string} params.account The account
* @param {string} params.successUrl The success url
* @return {Promise<Object>|Error} Return Promise with result
*/
createBill (billId, params) {
async createBill (billId, params) {
params.customFields = Object.assign({
apiClient: CLIENT_NAME,
apiClientVersion: packageJson.version
Expand All @@ -217,7 +219,11 @@ module.exports = class QiwiBillPaymentsAPI {
}
};

return this._requestBuilder(options);
let bill = await this._requestBuilder(options);
if (bill.payUrl && params.successUrl) {
bill.payUrl = `${bill.payUrl}&successUrl=${encodeURIComponent(params.successUrl)}`;
}
return bill;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions test/QiwiBillPaymentsAPI.spec.js
Expand Up @@ -13,6 +13,8 @@ const billId = qiwiApi.generateId();

const publicKey = testConfig.merchantSecretKey;

const successUrl = 'http://test.ru/';

const amount = 200.345;

const CLIENT_NAME = 'node_sdk';
Expand All @@ -29,7 +31,8 @@ const fields = {
customFields: {
city: 'Москва',
street: 'Арбат'
}
},
successUrl
};

describe('qiwi api v4', () => {
Expand All @@ -41,12 +44,13 @@ describe('qiwi api v4', () => {
it('creates payment form', () => {
const testLink = `https://oplata.qiwi.com/create?publicKey=${publicKey}&amount=${parseFloat(
amount
).toFixed(2)}&billId=${billId}&customFields[apiClient]=${CLIENT_NAME}&customFields[apiClientVersion]=${packageJson.version}`;
).toFixed(2)}&billId=${billId}&successUrl=http%3A%2F%2Ftest.ru%2F&customFields[apiClient]=${CLIENT_NAME}&customFields[apiClientVersion]=${packageJson.version}`;

link = qiwiApi.createPaymentForm({
publicKey,
amount,
billId
billId,
successUrl
});
assert.equal(link, testLink);
});
Expand Down

0 comments on commit a611338

Please sign in to comment.