Commit 4ab069319c1405686a3f74b6d6f041d05620d6cd
1 parent
3f0ff9875d
Exists in
master
paddingDestination
Showing 2 changed files with 23 additions and 0 deletions Side-by-side Diff
partner-bayarkilat.js
... | ... | @@ -218,6 +218,21 @@ function prepareRemoteProductCode(remoteProduct) { |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | +function paddingDestination(destination, width) { | |
222 | + if (!width) { | |
223 | + width = 13; | |
224 | + } | |
225 | + | |
226 | + if (destination.length > width) { | |
227 | + return destination; | |
228 | + } | |
229 | + | |
230 | + var padder = "000000000000000000000000000"; | |
231 | + | |
232 | + return (padder + destination).slice(-1 * width); | |
233 | +} | |
234 | + | |
221 | 235 | exports.start = start; |
222 | 236 | exports.topupRequest = topupRequest; |
223 | 237 | exports.prepareRemoteProductCode = prepareRemoteProductCode; |
238 | +exports.paddingDestination = paddingDestination; |
test.js
... | ... | @@ -12,4 +12,12 @@ describe('#partner-bayarkilat', function() { |
12 | 12 | product.nominal.should.equal('10000'); |
13 | 13 | }); |
14 | 14 | }); |
15 | + | |
16 | + describe('#paddingDestination', function() { | |
17 | + it('should return correct padded destination', function() { | |
18 | + partner.paddingDestination('0812').should.equal('0000000000812'); | |
19 | + partner.paddingDestination('0812', 14).should.equal('00000000000812'); | |
20 | + partner.paddingDestination('0812', 2).should.equal('0812'); | |
21 | + }); | |
22 | + }); | |
15 | 23 | }); |