Skip to content

Commit 3f830ae

Browse files
authored
[MIT-3611] Add passkey support (#226)
## Description - Add Typescript support for passkey feature - Accept `authentication` in request parameter - `PASSKEY` | `3DS` - Return `authenticated_by` in the response - Add other missing `Charge` response properties - `acquirer_reference_number` - `approval_code` - `can_perform_void` - `expired_at` - `funding_amount` - `funding_currency` - `linked_account` - `partially_refundable` - `reversed_at` - `transaction_fees` Please find more info about each properties here - https://docs.omise.co/charges-api ### Related links: https://opn-ooo.atlassian.net/browse/MIT-3611 ## Rollback procedure `default rollback procedure`
1 parent 4a6fe5e commit 3f830ae

4 files changed

Lines changed: 125 additions & 6 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const omise = require('./index');
4+
const { Authentication } = require('../..');
5+
6+
const card = {
7+
name: 'Omise',
8+
number: '5453011910000148',
9+
expiration_month: 2,
10+
expiration_year: '2030',
11+
security_code: '123',
12+
// Passkey requires either email or phone number
13+
email: 'dev@omise.co',
14+
phone_number: '+66000000000',
15+
};
16+
17+
(async () => {
18+
try {
19+
const token = await omise.tokens.create({ card })
20+
const charge = await omise.charges.create({
21+
amount: 100000,
22+
currency: 'thb',
23+
return_uri: 'http://example.com',
24+
card: token.id,
25+
authentication: Authentication.Passkey, // or just 'PASSKEY'
26+
})
27+
28+
console.log(charge.id, 'created with authentication', charge.authenticated_by);
29+
} catch (err) {
30+
console.log('error', err);
31+
}
32+
})();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import omiseClient from './index';
2+
import { Authentication } from 'omise';
3+
4+
const card = {
5+
name: 'Omise',
6+
number: '5453011910000148',
7+
expiration_month: 2,
8+
expiration_year: '2030',
9+
security_code: '123',
10+
// Passkey requires either email or phone number
11+
email: 'dev@omise.co',
12+
phone_number: '+66000000000',
13+
};
14+
15+
try {
16+
const token = await omiseClient.tokens.create({ card })
17+
const charge = await omiseClient.charges.create({
18+
amount: 100000,
19+
currency: 'thb',
20+
return_uri: 'http://example.com',
21+
card: token.id,
22+
authentication: Authentication.Passkey,
23+
})
24+
25+
console.log(charge.id, 'created with authentication', charge.authenticated_by);
26+
} catch (err) {
27+
console.log('error', err);
28+
}

index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
'use strict';
22
// Omise.co
33
const resource = require('./lib/apiResources');
4-
module.exports = function(config) {
4+
5+
const Omise = function(config) {
56
return resource.omiseResources(config);
67
};
8+
9+
// Enums
10+
const Scheme = {
11+
Http: 'http',
12+
Https: 'https',
13+
};
14+
15+
const AuthType = {
16+
PreAuth: 'pre_auth',
17+
FinalAuth: 'final_auth',
18+
};
19+
20+
const Authentication = {
21+
Passkey: 'PASSKEY',
22+
ThreeDS: '3DS',
23+
};
24+
25+
module.exports = Omise;
26+
module.exports.Authentication = Authentication;
27+
module.exports.Scheme = Scheme;
28+
module.exports.AuthType = AuthType;

types/index.d.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
declare function Omise(options: Omise.IOptions): Omise.IOmise;
77

8-
export = Omise;
9-
108
declare namespace Omise {
119
export interface IOptions {
1210
host?: string;
@@ -28,6 +26,11 @@ declare namespace Omise {
2826
FinalAuth = "final_auth",
2927
}
3028

29+
export enum Authentication {
30+
Passkey = "PASSKEY",
31+
ThreeDS = "3DS",
32+
}
33+
3134
export interface IOmise {
3235
account: Account.IAccountAPI;
3336
balance: Balance.IBalanceAPI;
@@ -202,6 +205,7 @@ declare namespace Omise {
202205
description?: string;
203206
amount: number;
204207
currency: string;
208+
authentication?: Authentication;
205209
authorization_type?: AuthType;
206210
capture?: boolean;
207211
card?: string;
@@ -231,8 +235,11 @@ declare namespace Omise {
231235
interface ICharge extends IBaseResponse {
232236
amount: number;
233237
currency: string;
238+
acquirer_reference_number: string | null;
239+
approval_code: string | null;
234240
authorization_type: AuthType;
235241
authorized_amount: number;
242+
authenticated_by: Authentication | null;
236243
captured_amount: number;
237244
description: string;
238245
device: any;
@@ -246,9 +253,12 @@ declare namespace Omise {
246253
paid: boolean;
247254
paid_at: string;
248255
transaction: string | Transactions.ITransaction;
256+
transaction_fees: { [key: string]: string };
249257
refunds: IListRefundResponse;
250258
failure_code: string;
251259
failure_message: string;
260+
funding_amount: number;
261+
funding_currency: string;
252262
merchant_advice: string | null;
253263
merchant_advice_code: string | null;
254264
missing_3ds_fields: string[];
@@ -257,26 +267,28 @@ declare namespace Omise {
257267
ip: string;
258268
dispute: string | Disputes.IResponse;
259269
expired: boolean;
260-
expired_at: string;
270+
expired_at: string | null;
261271
expires_at: string;
262272
interest: number;
263273
interest_vat: number;
264274
link: string | Links.ILink;
265275
net: number;
266276
platform_fee: IPlatformFee;
277+
partially_refundable: boolean;
267278
refundable: boolean;
268279
refunded_amount: number;
269280
return_uri: string;
270-
reversed_at: string;
281+
reversed_at: string | null;
271282
reversible: boolean;
272283
schedule: string | Schedules.ISchedule;
273284
terminal: any;
285+
can_perform_void: boolean;
274286
voided: boolean;
275287
zero_interest_installments: boolean;
276288
metadata: { [key: string]: any };
277289
source?: Sources.ISource;
278290
status: ChargeStatus;
279-
linked_account?: string;
291+
linked_account?: string | null;
280292
}
281293

282294
interface IListRefundResponse extends IOccurrences {
@@ -931,3 +943,28 @@ declare namespace Omise {
931943

932944
type ResponseCallback<R> = (err: any, resp: R) => void;
933945
}
946+
947+
declare namespace OmiseExports {
948+
export { Omise as default };
949+
export import Scheme = Omise.Scheme;
950+
export import AuthType = Omise.AuthType;
951+
export import Authentication = Omise.Authentication;
952+
export import Account = Omise.Account;
953+
export import Balance = Omise.Balance;
954+
export import Capability = Omise.Capability;
955+
export import Cards = Omise.Cards;
956+
export import Charges = Omise.Charges;
957+
export import Customers = Omise.Customers;
958+
export import Disputes = Omise.Disputes;
959+
export import Events = Omise.Events;
960+
export import Links = Omise.Links;
961+
export import Pagination = Omise.Pagination;
962+
export import Recipients = Omise.Recipients;
963+
export import Schedules = Omise.Schedules;
964+
export import Sources = Omise.Sources;
965+
export import Tokens = Omise.Tokens;
966+
export import Transactions = Omise.Transactions;
967+
export import Transfers = Omise.Transfers;
968+
}
969+
970+
export = OmiseExports;

0 commit comments

Comments
 (0)