@orboni/vendure-plugin 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,120 @@
1
+ import { ActiveOrderService, ChannelService, CreatePaymentErrorResult, CreatePaymentResult, CreateRefundResult, HistoryService, Order, OrderService, Payment, PaymentMethodService, PaymentMetadata, RequestContext, RequestContextService, SettlePaymentErrorResult, SettlePaymentResult, TransactionalConnection } from '@vendure/core';
2
+ import { Orboni } from 'orboni';
3
+ import { OrboniPluginOptions } from './constants';
4
+ /** The payment method's settings, from the dashboard. */
5
+ export interface OrboniArgs {
6
+ apiKey: string;
7
+ webhookSecret?: string;
8
+ successUrl?: string;
9
+ cancelUrl?: string;
10
+ }
11
+ export interface PaymentIntentInput {
12
+ paymentMethodCode: string;
13
+ successUrl?: string | null;
14
+ cancelUrl?: string | null;
15
+ }
16
+ export interface PaymentIntent {
17
+ url: string;
18
+ sessionId: string;
19
+ expiresAt: Date;
20
+ }
21
+ export interface WebhookAnswer {
22
+ status: number;
23
+ body: string;
24
+ }
25
+ export declare class OrboniService {
26
+ private readonly options;
27
+ private readonly activeOrderService;
28
+ private readonly orderService;
29
+ private readonly paymentMethodService;
30
+ private readonly historyService;
31
+ private readonly requestContextService;
32
+ private readonly connection;
33
+ private readonly channelService;
34
+ /** Work on one order at a time in this process; the order's row is locked too, for the other processes. */
35
+ private readonly locks;
36
+ /** When the check last read each recorded payment, in this process. */
37
+ private readonly lastRead;
38
+ constructor(options: OrboniPluginOptions, activeOrderService: ActiveOrderService, orderService: OrderService, paymentMethodService: PaymentMethodService, historyService: HistoryService, requestContextService: RequestContextService, connection: TransactionalConnection, channelService: ChannelService);
39
+ /**
40
+ * The Shop API's `createOrboniPaymentIntent`: moves the active order to
41
+ * ArrangingPayment and returns the payment page to send the buyer to.
42
+ * An open page of the same order, total and currency is sent again; any
43
+ * other open page of it is closed, so it can no longer be paid.
44
+ */
45
+ createPaymentIntent(ctx: RequestContext, input: PaymentIntentInput): Promise<PaymentIntent>;
46
+ /**
47
+ * The handler's createPayment: records a payment only as Orboni has it,
48
+ * read back with the merchant's key. Called by the webhook, and by the
49
+ * storefront's `addPaymentToOrder` with `{ sessionId }` when the buyer is
50
+ * back. A session not paid yet records nothing.
51
+ */
52
+ createPayment(ctx: RequestContext, order: Order, amount: number, args: OrboniArgs, metadata: PaymentMetadata): Promise<CreatePaymentResult | CreatePaymentErrorResult>;
53
+ /** The handler's settlePayment: an authorized payment is settled once Orboni says it is paid. */
54
+ settlePayment(payment: Payment, args: OrboniArgs): Promise<SettlePaymentResult | SettlePaymentErrorResult>;
55
+ /**
56
+ * The handler's createRefund. Orboni holds no money, so nothing is sent:
57
+ * the refund you sent from your own wallet is recorded against the
58
+ * session, where the dashboard shows it. Send the money first.
59
+ */
60
+ createRefund(ctx: RequestContext, reason: string | null | undefined, amount: number, order: Order, payment: Payment, args: OrboniArgs): Promise<CreateRefundResult>;
61
+ /**
62
+ * Orboni's webhook, at /payments/orboni/<channel token>. Events of
63
+ * sessions this channel did not make (another store on the same Orboni
64
+ * project) are answered 200 and left alone. Every change is made from the
65
+ * session as Orboni has it now, so an event sent twice, late or out of
66
+ * order changes nothing.
67
+ */
68
+ handleWebhook(channelToken: string, rawBody: Buffer | undefined, signature: string | undefined): Promise<WebhookAnswer>;
69
+ /**
70
+ * Payments whose webhook was lost or failed, read back from Orboni: every
71
+ * Orboni payment method of every channel lists its sessions paid, on their
72
+ * way or held in the last three days, and records those Vendure does not
73
+ * have; an authorized payment is read again until it is settled, a
74
+ * settled one every six hours for two days (money that left the chain).
75
+ * Run by the plugin's scheduled task (Vendure 3.3+, with a scheduler such
76
+ * as DefaultSchedulerPlugin); call it from a job of your own otherwise.
77
+ * One session that cannot be recorded stops no other.
78
+ */
79
+ checkPayments(): Promise<string>;
80
+ /** Sessions of this method paid, on their way or held lately that Vendure has not recorded as Orboni has them. */
81
+ private checkListed;
82
+ /** This method's payments in Vendure: authorized ones until settled, settled ones for two days. */
83
+ private checkRecorded;
84
+ /** Whether the order's newest note about this session says Vendure would not take its payment. */
85
+ private refused;
86
+ private checkOne;
87
+ /**
88
+ * Applies a session to its order in one transaction, the order's row
89
+ * locked: all of it is kept, or none. False when the channel has no such
90
+ * order; throws when it is to be tried again.
91
+ */
92
+ private record;
93
+ private apply;
94
+ /**
95
+ * The payment of this session already on the order, if any, as the other
96
+ * processes committed it. Called with the order's row locked: where rows
97
+ * can be locked it is read outside this transaction, since MySQL's
98
+ * repeatable read would show the snapshot Vendure's first read of the
99
+ * request took, before the lock. A locking read would see it too, but
100
+ * locks the gaps of the payments' index, where two new orders' payments
101
+ * wait on each other.
102
+ */
103
+ private recorded;
104
+ /** Locks the order's row until the transaction ends, where the database can (a call outside a transaction locks nothing). */
105
+ private lockOrder;
106
+ private rowLocks;
107
+ /** What payments already cover of the order. */
108
+ private coveredAmount;
109
+ private methodFor;
110
+ private argsOf;
111
+ client(args: OrboniArgs): Orboni;
112
+ /** The newest of the order's notes that names this session. */
113
+ private lastNote;
114
+ /** A note, unless the order's newest note about this session says the same: the check and the webhook come again. */
115
+ private noteOnce;
116
+ private note;
117
+ /** An Orboni call, its refusal turned into an error with Orboni's own words. */
118
+ private call;
119
+ private locked;
120
+ }