Skip to content

Commit

Permalink
add delete customer
Browse files Browse the repository at this point in the history
  • Loading branch information
p29hieu committed May 31, 2023
1 parent 9712407 commit 49679c8
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 8 deletions.
18 changes: 17 additions & 1 deletion example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,21 @@ const createCustomer = async () => {

const getCustomer = async (customer_id: string) => {
console.log('getCustomer');
const customer = await FincodeService.i.getCustomersId(customer_id)
const customer = await FincodeClientService.i.getCustomersId(customer_id)
console.log(customer);
return customer;
}

const updateCustomer = async (customer_id: string) => {
console.log('updateCustomer');
const customer = await FincodeService.i.putCustomersId(customer_id, {})
console.log(customer);
return customer;
}

const deleteCustomer = async (customer_id: string) => {
console.log('deleteCustomer');
const customer = await FincodeService.i.deleteCustomersId(customer_id)
console.log(customer);
return customer;
}
Expand Down Expand Up @@ -173,6 +187,8 @@ const paymentAfterAuthentication = async (orderId: string, data: FincodeNs.Payme
try {
// await createCustomer();
// await getCustomer(customer_id);
// await updateCustomer(customer_id);
// await deleteCustomer(customer_id);
// await createCard();
// await getCustomerCards(customerId);
// await createOrder();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fincode",
"version": "0.1.2",
"version": "0.1.3",
"description": "Type scripts for Fincode",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 9 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ export class FincodeClientService {
});
}

/**
*
* ref: https://docs.fincode.jp/api#tag/%E9%A1%A7%E5%AE%A2/operation/getCustomersId
*/
async getCustomersId(customerId: string): Promise<FincodeNs.CustomerInfo> {
const res = await this.service.get('/customers/{id}'.replace('{id}', customerId));
return res.data;
}

/**
*
* ref: https://docs.fincode.jp/api#tag/%E3%82%AB%E3%83%BC%E3%83%89/operation/getCustomersCustomer_idCards
Expand Down
31 changes: 25 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ export class FincodeService {
return res.data;
}

/**
*
* ref: https://docs.fincode.jp/api#tag/%E9%A1%A7%E5%AE%A2/operation/getCustomers
*/
async getCustomers(): Promise<FincodeNs.CustomersResponse> {
const res = await this.service.get('/customers');
return res.data;
}

/**
*
* ref: https://docs.fincode.jp/api#tag/%E9%A1%A7%E5%AE%A2/operation/getCustomersId
Expand All @@ -96,6 +105,16 @@ export class FincodeService {
return res.data;
}

/**
*
* ref: https://docs.fincode.jp/api#tag/%E9%A1%A7%E5%AE%A2/operation/deleteCustomersId
*/
async deleteCustomersId(customerId: string): Promise<FincodeNs.CustomerInfo> {
const endpoint = "/customers/{id}".replace("{id}", customerId);
const res = await this.service.delete(endpoint);
return res.data;
}

/**
*
* ref: https://docs.fincode.jp/api#tag/%E3%82%AB%E3%83%BC%E3%83%89/operation/postCustomersCustomer_idCards
Expand Down Expand Up @@ -176,7 +195,7 @@ export class FincodeService {
*/
async putPaymentsIdCapture(orderId: string, data: FincodeNs.ConfirmSales): Promise<FincodeNs.OrderDetail> {
const endpoint = "/payments/{id}/capture".replace("{id}", orderId);
const res = await this.service.put(endpoint, {
const res = await this.service.put(endpoint, {
...data,
...(data.method ? { method: data.method.toString() } : {})
});
Expand Down Expand Up @@ -211,9 +230,9 @@ export class FincodeService {
*
* ref: https://docs.fincode.jp/api#tag/%E6%B1%BA%E6%B8%88/paths/~1secure2~1%7Baccess_id%7D/put
*/
async perform3DS2Authentication(access_id: string, data: FincodeNs.Run3DS2Authentication): Promise<FincodeNs.Result3DS2Authentication> {
const endpoint = "/secure2/{access_id}".replace("{access_id}", access_id);
const res = await this.service.put(`${endpoint}`, data)
return res.data;
}
async perform3DS2Authentication(access_id: string, data: FincodeNs.Run3DS2Authentication): Promise<FincodeNs.Result3DS2Authentication> {
const endpoint = "/secure2/{access_id}".replace("{access_id}", access_id);
const res = await this.service.put(`${endpoint}`, data)
return res.data;
}
}
49 changes: 49 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,53 @@ export namespace FincodeNs {
*/
param: string
}

export type CustomersResponse = {
/**
* integer
*
* Total number of search results
*/
total_count: number;
/**
* integer
*
* last page
*/
last_page: number;

/**
* integer
*
* current page
*/
current_page: number

/**
* integer
*
* Maximum number of items per page
*/
limit: number;

/**
* string
*
* Link to next page
*/
link_next: string;

/**
* string
*
* Link to previous page
*/
link_previous: string;
/**
* Array of objects
*
* Customer data list
*/
list: CustomerInfo[]
}
}

0 comments on commit 49679c8

Please sign in to comment.