Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

fix: resuleCode required & chore v1.7.0 #19

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
FREE!!!
FREE!!!

ただし以下の三つを守る場合に限る

1. ちゃんとテストをする
テストが難しい場合は PullRequest でその旨を伝える
2. 他の形式に合わせる
Disscussion や twitter で聞いて良し
10 changes: 10 additions & 0 deletions deno_dist/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/EdamAme-x/paypax/test.yml?branch=main)](https://github.com/EdamAme-x/paypax/actions)
[![GitHub](https://img.shields.io/github/license/EdamAme-x/paypax)](https://github.com/EdamAme-x/paypax/blob/main/LICENSE)
[![npm](https://img.shields.io/npm/v/paypax)](https://www.npmjs.com/package/paypax)
[![npm](https://img.shields.io/npm/dm/paypax)](https://www.npmjs.com/package/paypax)
[![npm type definitions](https://img.shields.io/npm/types/paypax)](https://www.npmjs.com/package/paypax)
[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/EdamAme-x/paypax)](https://github.com/EdamAme-x/paypax/pulse)
[![GitHub last commit](https://img.shields.io/github/last-commit/EdamAme-x/paypax)](https://github.com/EdamAme-x/paypax/commits/main)
[![Deno badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Flatest-version%2Fx%2Fpaypax%2Fmod.ts)](https://doc.deno.land/https/deno.land/x/paypax/mod.ts)
[![Discord badge](https://img.shields.io/discord/1115195558743781408?label=Discord&logo=Discord)](https://discord.gg/ctkpaarr)

# PayPax
PayPay UnOffical api Rapper Library | Various PayPay operations can be automated, from login to balance transfer and confirmation.
Open Source Software 🎁
Expand Down
38 changes: 23 additions & 15 deletions deno_dist/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ export class PayPay {
'resultMessage' in result['header']
) {
if (
result['header']['resultCode'] === 'S0001' ||
result['header']['resultCode'] === 'S9999'
result['header']['resultCode'] === 'S0001'
) {
// Refresh
await this.login({
Expand Down Expand Up @@ -239,10 +238,10 @@ export class PayPay {
)

if (!response.ok) {
throw new PayPayError('Get balance failed', 1).fire()
return parseBalanceContext(result, false)
}

return parseBalanceContext(result)
return parseBalanceContext(result, true)
}

async getUserInfo(): Promise<ResponseUserInfo> {
Expand All @@ -258,10 +257,10 @@ export class PayPay {
)

if (!response.ok) {
throw new PayPayError('Get user info failed', 1).fire()
return parseUserInfoContext(result, false)
}

return parseUserInfoContext(result)
return parseUserInfoContext(result, true)
}

async createLink(amount: number, passcode?: string): Promise<ResponseCreateLink> {
Expand Down Expand Up @@ -295,10 +294,10 @@ export class PayPay {
)

if (!response.ok) {
throw new PayPayError('Create link failed', 1).fire()
return parseCreateLink(result, false)
}

return parseCreateLink(result)
return parseCreateLink(result, true)
}

async getLink(link: string): Promise<ResponseGetLink> {
Expand All @@ -320,10 +319,10 @@ export class PayPay {
)

if (!response.ok) {
throw new PayPayError('Link is not found', 1).fire()
return parseGetLink(result, false)
}

return parseGetLink(result)
return parseGetLink(result, true)
}

async receiveLink(link: string, passcode?: string): Promise<ResponseReceiveLink | undefined> {
Expand Down Expand Up @@ -364,10 +363,10 @@ export class PayPay {
)

if (!response.ok) {
throw new PayPayError('Receive link failed', 1).fire()
return parseReceiveLink(result, false)
}

return parseReceiveLink(result)
return parseReceiveLink(result, true)
}catch (_e) {
throw new PayPayError('Invalid link', 1).fire()
}
Expand Down Expand Up @@ -401,7 +400,10 @@ export class PayPay {
)

if (!response.ok) {
throw new PayPayError('Reject link failed', 1).fire()
return {
success: false,
raw: result
}
}

return {
Expand Down Expand Up @@ -443,7 +445,10 @@ export class PayPay {
)

if (!response.ok) {
throw new PayPayError('Send money failed', 1).fire()
return {
success: false,
raw: result
}
}

if (result.header.resultCode === 'S9999') {
Expand All @@ -469,7 +474,10 @@ export class PayPay {
})

if (!response.ok) {
throw new PayPayError('Request path failed', 1).fire()
return {
success: false,
raw: result
}
}

return {
Expand Down
7 changes: 6 additions & 1 deletion deno_dist/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export type ResponseFail = {

export type ResponseBalance = {
success: boolean
message: string
total: number
currency: 'JPY' | string
updated_at: string
Expand All @@ -91,6 +92,7 @@ export type ResponseBalance = {

export type ResponseUserInfo = {
success: boolean
message: string
id: number
user_id: string
state: string
Expand All @@ -115,8 +117,9 @@ export type ResponseUserInfo = {

export type ResponseCreateLink = {
success: boolean
message: string
orderId: string
orderStatus: 'PENDING'
orderStatus: string
link: string
transactionAt: string
expiry: string
Expand All @@ -133,6 +136,7 @@ export type ResponseCreateLink = {

export type ResponseGetLink = {
success: boolean
message: string
orderId: string
orderType: string
description: string
Expand All @@ -159,6 +163,7 @@ export type ResponseGetLink = {

export type ResponseReceiveLink = {
success: boolean
message: string
messageId: string
chatRoomId: string
orderStatus: string
Expand Down
51 changes: 51 additions & 0 deletions deno_dist/utils/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,55 @@ describe('Util', () => {
expect(password).toBe('ctkpaarR2')
expect(uuid).toBe('a9b3d5c6-7d8e-9f0a-bcde-fghijk')
})

test('prase fail response', () => {
const failResponse = {
header: {
resultCode: 'S0001',
resultMessage: 'Invalid anyone',
},
payload: {
paypay: 'resultCode',
oosugi: 'dounikashite'
}
}

expect(util.parseBalanceContext(failResponse, false)).toStrictEqual({
success: false,
message: 'Invalid anyone',
total: 0,
currency: 'JPY',
updated_at: new Date(0).toISOString(),
raw: failResponse
})
})

test('parse resultMessage', () => {
const eg1 = {
header: {
resultCode: 'S0001',
resultMessage: 'Example 1',
},
payload: {
paypay: 'resultCode',
oosugi: 'dounikashite'
}
}

expect(util.parseResultMessage(eg1)).toBe('Example 1')

const eg2 = {
header: {},
payload: {
paypay: 'resultCode',
oosugi: 'dounikashite'
}
}

expect(util.parseResultMessage(eg2)).toBe('unknown')

const eg3 = {}

expect(util.parseResultMessage(eg3)).toBe('unknown')
})
})
Loading