diff --git a/examples/javascript/create_passkey_charge.js b/examples/javascript/create_passkey_charge.js new file mode 100644 index 0000000..fecc32e --- /dev/null +++ b/examples/javascript/create_passkey_charge.js @@ -0,0 +1,32 @@ +'use strict'; + +const omise = require('./index'); +const { Authentication } = require('../..'); + +const card = { + name: 'Omise', + number: '5453011910000148', + expiration_month: 2, + expiration_year: '2030', + security_code: '123', + // Passkey requires either email or phone number + email: 'dev@omise.co', + phone_number: '+66000000000', +}; + +(async () => { + try { + const token = await omise.tokens.create({ card }) + const charge = await omise.charges.create({ + amount: 100000, + currency: 'thb', + return_uri: 'http://example.com', + card: token.id, + authentication: Authentication.Passkey, // or just 'PASSKEY' + }) + + console.log(charge.id, 'created with authentication', charge.authenticated_by); + } catch (err) { + console.log('error', err); + } +})(); diff --git a/examples/typescript/src/create_passkey_charge.ts b/examples/typescript/src/create_passkey_charge.ts new file mode 100644 index 0000000..d8f9933 --- /dev/null +++ b/examples/typescript/src/create_passkey_charge.ts @@ -0,0 +1,28 @@ +import omiseClient from './index'; +import { Authentication } from 'omise'; + +const card = { + name: 'Omise', + number: '5453011910000148', + expiration_month: 2, + expiration_year: '2030', + security_code: '123', + // Passkey requires either email or phone number + email: 'dev@omise.co', + phone_number: '+66000000000', +}; + +try { + const token = await omiseClient.tokens.create({ card }) + const charge = await omiseClient.charges.create({ + amount: 100000, + currency: 'thb', + return_uri: 'http://example.com', + card: token.id, + authentication: Authentication.Passkey, + }) + + console.log(charge.id, 'created with authentication', charge.authenticated_by); +} catch (err) { + console.log('error', err); +} diff --git a/index.js b/index.js index b07e3b0..b241234 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,28 @@ 'use strict'; // Omise.co const resource = require('./lib/apiResources'); -module.exports = function(config) { + +const Omise = function(config) { return resource.omiseResources(config); }; + +// Enums +const Scheme = { + Http: 'http', + Https: 'https', +}; + +const AuthType = { + PreAuth: 'pre_auth', + FinalAuth: 'final_auth', +}; + +const Authentication = { + Passkey: 'PASSKEY', + ThreeDS: '3DS', +}; + +module.exports = Omise; +module.exports.Authentication = Authentication; +module.exports.Scheme = Scheme; +module.exports.AuthType = AuthType; diff --git a/types/index.d.ts b/types/index.d.ts index acde79f..a06e933 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -5,8 +5,6 @@ declare function Omise(options: Omise.IOptions): Omise.IOmise; -export = Omise; - declare namespace Omise { export interface IOptions { host?: string; @@ -28,6 +26,11 @@ declare namespace Omise { FinalAuth = "final_auth", } + export enum Authentication { + Passkey = "PASSKEY", + ThreeDS = "3DS", + } + export interface IOmise { account: Account.IAccountAPI; balance: Balance.IBalanceAPI; @@ -202,6 +205,7 @@ declare namespace Omise { description?: string; amount: number; currency: string; + authentication?: Authentication; authorization_type?: AuthType; capture?: boolean; card?: string; @@ -231,8 +235,11 @@ declare namespace Omise { interface ICharge extends IBaseResponse { amount: number; currency: string; + acquirer_reference_number: string | null; + approval_code: string | null; authorization_type: AuthType; authorized_amount: number; + authenticated_by: Authentication | null; captured_amount: number; description: string; device: any; @@ -246,9 +253,12 @@ declare namespace Omise { paid: boolean; paid_at: string; transaction: string | Transactions.ITransaction; + transaction_fees: { [key: string]: string }; refunds: IListRefundResponse; failure_code: string; failure_message: string; + funding_amount: number; + funding_currency: string; merchant_advice: string | null; merchant_advice_code: string | null; missing_3ds_fields: string[]; @@ -257,26 +267,28 @@ declare namespace Omise { ip: string; dispute: string | Disputes.IResponse; expired: boolean; - expired_at: string; + expired_at: string | null; expires_at: string; interest: number; interest_vat: number; link: string | Links.ILink; net: number; platform_fee: IPlatformFee; + partially_refundable: boolean; refundable: boolean; refunded_amount: number; return_uri: string; - reversed_at: string; + reversed_at: string | null; reversible: boolean; schedule: string | Schedules.ISchedule; terminal: any; + can_perform_void: boolean; voided: boolean; zero_interest_installments: boolean; metadata: { [key: string]: any }; source?: Sources.ISource; status: ChargeStatus; - linked_account?: string; + linked_account?: string | null; } interface IListRefundResponse extends IOccurrences { @@ -931,3 +943,28 @@ declare namespace Omise { type ResponseCallback = (err: any, resp: R) => void; } + +declare namespace OmiseExports { + export { Omise as default }; + export import Scheme = Omise.Scheme; + export import AuthType = Omise.AuthType; + export import Authentication = Omise.Authentication; + export import Account = Omise.Account; + export import Balance = Omise.Balance; + export import Capability = Omise.Capability; + export import Cards = Omise.Cards; + export import Charges = Omise.Charges; + export import Customers = Omise.Customers; + export import Disputes = Omise.Disputes; + export import Events = Omise.Events; + export import Links = Omise.Links; + export import Pagination = Omise.Pagination; + export import Recipients = Omise.Recipients; + export import Schedules = Omise.Schedules; + export import Sources = Omise.Sources; + export import Tokens = Omise.Tokens; + export import Transactions = Omise.Transactions; + export import Transfers = Omise.Transfers; +} + +export = OmiseExports;