feat(medusa-js): Add payment and payment collections clients (#2608)
This commit is contained in:
committed by
GitHub
parent
3de553c27f
commit
ccfc5f666d
@@ -8,6 +8,7 @@ import CustomersResource from "./resources/customers"
|
||||
import GiftCardsResource from "./resources/gift-cards"
|
||||
import OrdersResource from "./resources/orders"
|
||||
import OrderEditsResource from "./resources/order-edits"
|
||||
import PaymentCollectionsResource from "./resources/payment-collections"
|
||||
import PaymentMethodsResource from "./resources/payment-methods"
|
||||
import ProductsResource from "./resources/products"
|
||||
import ProductTypesResource from "./resources/product-types"
|
||||
@@ -37,6 +38,7 @@ class Medusa {
|
||||
public collections: CollectionsResource
|
||||
public giftCards: GiftCardsResource
|
||||
public paymentMethods: PaymentMethodsResource
|
||||
public paymentCollections: PaymentCollectionsResource
|
||||
|
||||
constructor(config: Config) {
|
||||
this.client = new Client(config)
|
||||
@@ -59,6 +61,7 @@ class Medusa {
|
||||
this.collections = new CollectionsResource(this.client)
|
||||
this.giftCards = new GiftCardsResource(this.client)
|
||||
this.paymentMethods = new PaymentMethodsResource(this.client)
|
||||
this.paymentCollections = new PaymentCollectionsResource(this.client)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ import AdminTaxRatesResource from "./tax-rates"
|
||||
import AdminUploadsResource from "./uploads"
|
||||
import AdminUsersResource from "./users"
|
||||
import AdminVariantsResource from "./variants"
|
||||
import AdminPaymentCollectionsResource from "./payment-collections"
|
||||
import AdminPaymentsResource from "./payments"
|
||||
|
||||
class Admin extends BaseResource {
|
||||
public auth = new AdminAuthResource(this.client)
|
||||
@@ -63,6 +65,8 @@ class Admin extends BaseResource {
|
||||
public notifications = new AdminNotificationsResource(this.client)
|
||||
public taxRates = new AdminTaxRatesResource(this.client)
|
||||
public uploads = new AdminUploadsResource(this.client)
|
||||
public paymentCollections = new AdminPaymentCollectionsResource(this.client)
|
||||
public payments = new AdminPaymentsResource(this.client)
|
||||
}
|
||||
|
||||
export default Admin
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
AdminUpdatePaymentCollectionRequest,
|
||||
AdminPaymentCollectionDeleteRes,
|
||||
AdminPaymentCollectionRes,
|
||||
GetPaymentCollectionsParams,
|
||||
} from "@medusajs/medusa"
|
||||
import { ResponsePromise } from "../../typings"
|
||||
import BaseResource from "../base"
|
||||
import qs from "qs"
|
||||
|
||||
class AdminPaymentCollectionsResource extends BaseResource {
|
||||
retrieve(
|
||||
id: string,
|
||||
query?: GetPaymentCollectionsParams,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminPaymentCollectionRes> {
|
||||
let path = `/admin/payment-collections/${id}`
|
||||
|
||||
if (query) {
|
||||
const queryString = qs.stringify(query)
|
||||
path += `?${queryString}`
|
||||
}
|
||||
|
||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||
}
|
||||
|
||||
update(
|
||||
id: string,
|
||||
payload: AdminUpdatePaymentCollectionRequest,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminPaymentCollectionRes> {
|
||||
const path = `/admin/payment-collections/${id}`
|
||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||
}
|
||||
|
||||
delete(
|
||||
id: string,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminPaymentCollectionDeleteRes> {
|
||||
const path = `/admin/payment-collections/${id}`
|
||||
return this.client.request("DELETE", path, undefined, {}, customHeaders)
|
||||
}
|
||||
}
|
||||
|
||||
export default AdminPaymentCollectionsResource
|
||||
45
packages/medusa-js/src/resources/admin/payments.ts
Normal file
45
packages/medusa-js/src/resources/admin/payments.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
AdminPaymentRes,
|
||||
AdminPostPaymentRefundsReq,
|
||||
AdminRefundRes,
|
||||
GetPaymentsParams,
|
||||
} from "@medusajs/medusa"
|
||||
import qs from "qs"
|
||||
import { ResponsePromise } from "../../typings"
|
||||
import BaseResource from "../base"
|
||||
|
||||
class AdminPaymentsResource extends BaseResource {
|
||||
retrieve(
|
||||
id: string,
|
||||
query?: GetPaymentsParams,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminPaymentRes> {
|
||||
let path = `/admin/payments/${id}`
|
||||
|
||||
if (query) {
|
||||
const queryString = qs.stringify(query)
|
||||
path = `/admin/payments/${id}?${queryString}`
|
||||
}
|
||||
|
||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||
}
|
||||
|
||||
capturePayment(
|
||||
id: string,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminPaymentRes> {
|
||||
const path = `/admin/payments/${id}/capture`
|
||||
return this.client.request("POST", path, undefined, {}, customHeaders)
|
||||
}
|
||||
|
||||
refundPayment(
|
||||
id: string,
|
||||
payload: AdminPostPaymentRefundsReq,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminRefundRes> {
|
||||
const path = `/admin/payments/${id}/refund`
|
||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||
}
|
||||
}
|
||||
|
||||
export default AdminPaymentsResource
|
||||
56
packages/medusa-js/src/resources/payment-collections.ts
Normal file
56
packages/medusa-js/src/resources/payment-collections.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
GetPaymentCollectionsParams,
|
||||
StoreManagePaymentCollectionSessionRequest,
|
||||
StoreRefreshPaymentCollectionSessionRequest,
|
||||
StorePaymentCollectionSessionRes,
|
||||
StorePaymentCollectionRes,
|
||||
} from "@medusajs/medusa"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
import qs from "qs"
|
||||
|
||||
class PaymentCollectionsResource extends BaseResource {
|
||||
retrieve(
|
||||
id: string,
|
||||
query?: GetPaymentCollectionsParams,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<StorePaymentCollectionRes> {
|
||||
let path = `/store/payment-collections/${id}`
|
||||
|
||||
if (query) {
|
||||
const queryString = qs.stringify(query)
|
||||
path += `?${queryString}`
|
||||
}
|
||||
|
||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||
}
|
||||
|
||||
authorize(
|
||||
id: string,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<StorePaymentCollectionRes> {
|
||||
const path = `/store/payment-collections/${id}/authorize`
|
||||
return this.client.request("POST", path, undefined, {}, customHeaders)
|
||||
}
|
||||
|
||||
manageSessions(
|
||||
id: string,
|
||||
payload: StoreManagePaymentCollectionSessionRequest,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<StorePaymentCollectionRes> {
|
||||
const path = `/store/payment-collections/${id}/sessions`
|
||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||
}
|
||||
|
||||
refreshPaymentSession(
|
||||
id: string,
|
||||
session_id: string,
|
||||
payload: StoreRefreshPaymentCollectionSessionRequest,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<StorePaymentCollectionSessionRes> {
|
||||
const path = `/store/payment-collections/${id}/sessions/${session_id}/refresh`
|
||||
return this.client.request("POST", path, payload, {}, customHeaders)
|
||||
}
|
||||
}
|
||||
|
||||
export default PaymentCollectionsResource
|
||||
Reference in New Issue
Block a user