-
Notifications
You must be signed in to change notification settings - Fork 0
/
InteractiveFlowIntegration.php
150 lines (131 loc) · 4.19 KB
/
InteractiveFlowIntegration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
declare(strict_types=1);
// Copyright 2024 Argo Navis Dev. All rights reserved.
// Use of this source code is governed by a license that can be
// found in the LICENSE file.
namespace App\Stellar\Sep24Interactive;
use App\Stellar\Sep38Quote\Sep38Helper;
use ArgoNavis\PhpAnchorSdk\callback\IInteractiveFlowIntegration;
use ArgoNavis\PhpAnchorSdk\callback\InteractiveDepositRequest;
use ArgoNavis\PhpAnchorSdk\callback\InteractiveTransactionResponse;
use ArgoNavis\PhpAnchorSdk\callback\InteractiveWithdrawRequest;
use ArgoNavis\PhpAnchorSdk\callback\TransactionHistoryRequest;
use ArgoNavis\PhpAnchorSdk\callback\Sep24TransactionResponse;
use ArgoNavis\PhpAnchorSdk\exception\AnchorFailure;
use ArgoNavis\PhpAnchorSdk\shared\Sep24AssetInfo;
use ArgoNavis\PhpAnchorSdk\shared\Sep38Quote;
class InteractiveFlowIntegration implements IInteractiveFlowIntegration
{
/**
* @inheritDoc
*/
public function supportedAssets(): array
{
return Sep24Helper::getSupportedAssets();
}
/**
* @inheritDoc
*/
public function getAsset(string $code, ?string $issuer = null): ?Sep24AssetInfo
{
return Sep24Helper::getAssetInfo($code, $issuer);
}
/**
* @inheritDoc
*/
public function getFee(string $operation, string $assetCode, float $amount, ?string $type = null): float
{
throw new AnchorFailure('fee endpoint is not supported');
}
/**
* @inheritDoc
*/
public function withdraw(InteractiveWithdrawRequest $request): InteractiveTransactionResponse
{
if ($request->hasKycData()) {
Sep24Helper::createOrUpdateCustomer($request);
}
$sep24Transaction = Sep24Helper::newTransaction($request);
return new InteractiveTransactionResponse(
type: 'interactive_customer_info_needed',
url: Sep24Helper::createInteractivePopupUrl($sep24Transaction->id),
id: $sep24Transaction->id);
}
/**
* @inheritDoc
*/
public function deposit(InteractiveDepositRequest $request): InteractiveTransactionResponse
{
if ($request->hasKycData()) {
Sep24Helper::createOrUpdateCustomer($request);
}
$sep24Transaction = Sep24Helper::newTransaction($request);
return new InteractiveTransactionResponse(
type: 'interactive_customer_info_needed',
url: Sep24Helper::createInteractivePopupUrl($sep24Transaction->id),
id: $sep24Transaction->id);
}
/**
* @inheritDoc
*/
public function findTransactionById(
string $id,
string $accountId,
?string $accountMemo = null,
?string $lang = null,
): ?Sep24TransactionResponse
{
return Sep24Helper::getTransaction(
accountId: $accountId,
memo: $accountMemo,
id: $id,
);
}
/**
* @inheritDoc
*/
public function findTransactionByStellarTransactionId(
string $stellarTransactionId,
string $accountId,
?string $accountMemo = null,
?string $lang = null,
): ?Sep24TransactionResponse
{
return Sep24Helper::getTransaction(
accountId: $accountId,
memo: $accountMemo,
stellarTxId: $stellarTransactionId,
);
}
/**
* @inheritDoc
*/
public function findTransactionByExternalTransactionId(
string $externalTransactionId,
string $accountId,
?string $accountMemo = null,
?string $lang = null,
): ?Sep24TransactionResponse
{
return Sep24Helper::getTransaction(
accountId: $accountId,
memo: $accountMemo,
externalTxId: $externalTransactionId,
);
}
/**
* @inheritDoc
*/
public function getTransactionHistory(
TransactionHistoryRequest $request,
string $accountId,
?string $accountMemo = null,
): ?array
{
return Sep24Helper::getTransactionHistory($request, $accountId, $accountMemo);
}
public function getQuoteById(string $quoteId, string $accountId, ?string $accountMemo = null): Sep38Quote
{
return Sep38Helper::getQuoteById($quoteId, $accountId, $accountMemo);
}
}