export type Delivery = {street?: string | undefined, postalBox?: string | undefined, postalCode?: string | undefined, city?: string | undefined, state?: string | undefined, countryCode?: string | undefined, name?: string | undefined, recipientName?: string | undefined, recipientEmail?: string | undefined, recipientPhone?: string | undefined}; export type Buyer = {extCustomerId?: string | undefined, email?: string | undefined, phone?: string | undefined, firstName?: string | undefined, lastName?: string | undefined, nin?: string | undefined, language?: string | undefined, birthDate?: unknown | undefined, delivery?: Delivery | undefined}; export type Products = Array<{name: string, unitPrice: string, quantity: string, virtual?: boolean | undefined}>; export type ShippingMethods = Array<{country: string, price: number, name: string}>; export type ShoppingCarts = Array<{extCustomerId: string, amount: number, fee?: string | undefined, shippingMethods?: ShippingMethods | undefined, products: Products}>; export type Order = {shippingMethod?: ({country?: string | undefined, price?: string | undefined, name?: string | undefined}) | undefined, orderId?: string | undefined, extOrderId?: string | undefined, orderCreateDate?: string | undefined, notifyUrl?: string | undefined, customerIp?: string | undefined, merchantPosId?: string | undefined, description?: string | undefined, additionalDescription?: string | undefined, validityTime?: string | undefined, currencyCode?: string | undefined, totalAmount?: string | undefined, capturedAmount?: string | undefined, buyer?: Buyer | undefined, payMethod?: ({amount?: string | undefined, type?: ('PBL' | 'CARD_TOKEN' | 'INSTALLMENTS') | undefined}) | undefined, products?: Products | undefined, shoppingCarts?: ShoppingCarts | undefined, merchantFunds?: (Array<{type?: 'COUPON' | undefined, value?: string | undefined, amount?: string | undefined}>) | undefined, status?: ('NEW' | 'PENDING' | 'WAITING_FOR_CONFIRMATION' | 'COMPLETED' | 'CANCELED') | undefined}; export type Properties = Array<{name?: string | undefined, value?: string | undefined}>; export type PaymentFlow = 'APPLE_PAY' | 'CARD' | 'CARD_INSTALLMENTS' | 'CLICK_TO_PAY' | 'FIRST_ONE_CLICK_CARD' | 'GOOGLE_PAY' | 'GOOGLE_PAY_TOKENIZED' | 'VISA_MOBILE' | 'ONE_CLICK_CARD' | 'ONE_CLICK_CARD_RECURRING' | 'ONE_CLICK_MAIL_ORDER' | 'ONE_CLICK_MAIL_RECURRING' | 'ONE_CLICK_PHONE_ORDER' | 'ONE_CLICK_PHONE_RECURRING' | 'BLIK_PBL' | 'BLIK_AUTHORIZATION_CODE' | 'BLIK_AUTHORIZATION_CODE_WITH_UID_TOKEN_REGISTERING' | 'BLIK_UID_TOKEN' | 'BLIK_AUTHORIZATION_CODE_WITH_PAYID_TOKEN_TYPE_O_REGISTERING' | 'BLIK_PAYID_TOKEN_TYPE_O' | 'PBL'; export type Card = {maskedNumber?: string | undefined, scheme?: string | undefined, issuerName?: string | undefined, issuerCountryCode?: string | undefined, countryCode?: string | undefined, classification?: string | undefined, profile?: string | undefined}; export type Authentication = {eci?: string | undefined, threeDs?: ({status?: string | undefined, description?: string | undefined, frictionlessIndicator?: string | undefined}) | undefined}; export type Authorization = {amount?: string | undefined, currencyCode?: string | undefined, serviceProcessingType?: ('PSP' | 'TSP') | undefined, status?: ('AUTHORIZED' | 'SOFT_DECLINED' | 'REJECTED' | 'PENDING') | undefined, createDate?: string | undefined, resultDate?: string | undefined, validUntil?: string | undefined, payType?: string | undefined, paymentFlow?: PaymentFlow | undefined, payTypeDetails?: ({responseCode?: string | undefined, responseCodeDescription?: string | undefined, firstTransactionId?: string | undefined, schemeTransactionId?: string | undefined, schemeResponseCode?: string | undefined, retrievalReferenceNumber?: string | undefined, acquirerCode?: string | undefined, card?: Card | undefined, authentication?: Authentication | undefined} | {resultCode?: string | undefined, txRef?: string | undefined, extTxRef?: string | undefined, buid?: string | undefined} | {orderId?: string | undefined, invoiceId?: string | undefined}) | undefined}; export type Capture = {amount?: string | undefined, currencyCode?: string | undefined, date?: string | undefined, payTypeDetails?: ({retrievalReferenceNumber?: string | undefined, acquirerCode?: string | undefined} | {orderId?: string | undefined, invoiceId?: string | undefined, feeAmount?: string | undefined, sellerProtectionStatus?: string | undefined, sellerProtectionDisputeCategories?: Array | undefined}) | undefined}; export type Fee = {amount?: string | undefined, currencyCode?: string | undefined, type?: string | undefined}; export type EnrichedOrder = {shippingMethod?: ({country?: string | undefined, price?: string | undefined, name?: string | undefined}) | undefined, orderId?: string | undefined, extOrderId?: string | undefined, orderCreateDate?: string | undefined, notifyUrl?: string | undefined, customerIp?: string | undefined, merchantPosId?: string | undefined, description?: string | undefined, additionalDescription?: string | undefined, validityTime?: string | undefined, currencyCode?: string | undefined, totalAmount?: string | undefined, orderUrl?: string | undefined, capturedAmount?: string | undefined, buyer?: Buyer | undefined, payMethod?: ({amount?: string | undefined, type?: ('PBL' | 'CARD_TOKEN' | 'INSTALLMENTS') | undefined}) | undefined, products?: Products | undefined, shoppingCarts?: ShoppingCarts | undefined, merchantFunds?: (Array<{type?: 'COUPON' | undefined, value?: string | undefined, amount?: string | undefined}>) | undefined, authorization?: Authorization | undefined, capture?: Capture | undefined, fees?: Array | undefined, mcpData?: ({amount?: string | undefined, currencyCode?: string | undefined, rate?: string | undefined}) | undefined, status?: ('NEW' | 'PENDING' | 'WAITING_FOR_CONFIRMATION' | 'COMPLETED' | 'CANCELED') | undefined}; export type CreateApiYourNotifyUrlArgs = {'Content-Type'?: string | undefined, body: {order?: Order | undefined, properties?: Properties | undefined} | {order?: EnrichedOrder | undefined, properties?: Properties | undefined} | {orderId?: string | undefined, extOrderId?: string | undefined, refund?: ({refundId?: string | undefined, extRefundId?: string | undefined, amount?: string | undefined, currencyCode?: string | undefined, status?: ('FINALIZED' | 'CANCELLED') | undefined, statusDateTime?: string | undefined, reason?: string | undefined, reasonDescription?: string | undefined, refundDate?: string | undefined}) | undefined}}; export type CreateApiYourNotifyUrlOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * order/refund status change * * POST /your-notify-url */ export const createApiYourNotifyUrl = async (args: CreateApiYourNotifyUrlArgs, options?: CreateApiYourNotifyUrlOptions) => { const {baseUrl = "https://secure.payu.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/your-notify-url${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };