@polymorphism-tech/morph-spec 11.2.0 → 11.3.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.
- package/README.md +3 -2
- package/bin/morph-spec.js +7 -7
- package/docs/CHEATSHEET.md +1 -1
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +1 -1
- package/framework/MORPH.md +2 -2
- package/framework/agents.json +4 -4
- package/framework/docs/CLI.md +19 -11
- package/framework/evals/review-checklist.md +26 -2
- package/framework/hooks/README.md +3 -2
- package/framework/hooks/claude-code/core/graph-refresh-kick.js +2 -2
- package/framework/mcp/registry.json +15 -15
- package/framework/rules/ai-agents-standards.md +9 -1
- package/framework/rules/gsap-standards.md +8 -0
- package/framework/rules/mcp-standards.md +10 -0
- package/framework/schemas/config.schema.json +7 -0
- package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
- package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
- package/framework/skills/core/morph-apply/SKILL.md +4 -3
- package/framework/skills/core/morph-plan/SKILL.md +1 -1
- package/framework/skills/core/morph-uiux/SKILL.md +1 -1
- package/framework/standards/STANDARDS.json +8 -4
- package/framework/standards/STANDARDS.meta.json +1 -1
- package/framework/standards/ai-agents/agent-archetypes.md +1 -1
- package/framework/standards/ai-agents/middleware-patterns.md +0 -2
- package/framework/standards/ai-agents/prompt-sources.md +2 -2
- package/framework/standards/ai-agents/providers/model-registry.md +9 -12
- package/framework/standards/ai-agents/rag-custom-pgvector.md +2 -9
- package/framework/standards/frontend/design-system/ai-image-generation.md +1 -1
- package/framework/standards/infrastructure/docker/local-compose-isolation.md +2 -2
- package/framework/standards/integration/mcp/mcp-tools.md +124 -266
- package/framework/templates/README.md +52 -82
- package/framework/templates/REGISTRY.json +0 -206
- package/framework/templates/code/sql/ai-agents/agent-prompts-migration.sql.template +3 -4
- package/framework/templates/context/design-system.md +1 -1
- package/framework/templates/docs/plan.md +1 -1
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/model-registry.v2.json +1 -1
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaDisclosureTests.cs +1 -1
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Morph.AiKit.Tests.csproj +2 -4
- package/framework/templates/frontend/nextjs/gsap-scroll-section.tsx.hbs +13 -17
- package/framework/templates/infrastructure/github/README.md +10 -13
- package/package.json +9 -3
- package/src/commands/mcp/manual-setup.js +95 -0
- package/src/commands/mcp/mcp-setup.js +23 -191
- package/src/commands/project/doctor.js +6 -16
- package/src/commands/project/init-contract.js +2 -2
- package/src/commands/project/init.js +15 -133
- package/src/commands/project/stack-scan.js +6 -14
- package/src/commands/project/stack-set.js +1 -1
- package/src/commands/project/standards.js +1 -2
- package/src/commands/project/update.js +52 -66
- package/src/commands/scaffold/scaffold.js +28 -7
- package/src/lib/ai/ai-project-scan.js +1 -4
- package/src/lib/ai/code-audit.js +1 -6
- package/src/lib/ai/registry-audit.js +2 -1
- package/src/lib/config/project-config.js +3 -2
- package/src/lib/contract/apply.js +2 -1
- package/src/lib/contract/merge.js +1 -0
- package/src/lib/contract/scan.js +5 -5
- package/src/lib/detectors/claude-config-detector.js +45 -47
- package/src/lib/detectors/mcp-config.js +2 -1
- package/src/lib/diff/diff-lines.js +2 -7
- package/src/lib/graph/graph-loader.js +2 -1
- package/src/lib/graph/graphifyignore.js +2 -1
- package/src/lib/installers/install-manifest.js +56 -0
- package/src/lib/installers/mcp-installer.js +14 -5
- package/src/lib/installers/rules-installer.js +9 -15
- package/src/lib/installers/stack-assets.js +42 -21
- package/src/lib/installers/stack-sync.js +12 -12
- package/src/lib/installers/stack-tooling.js +4 -3
- package/src/lib/json-file.js +9 -0
- package/src/lib/plan/artifact-vocabulary.js +1 -1
- package/src/lib/plan/checks.js +3 -2
- package/src/lib/plan/media.js +3 -3
- package/src/lib/plan/plan-parser.js +5 -10
- package/src/lib/review-reports.js +5 -4
- package/src/lib/stack/stack-scan.js +1 -1
- package/src/lib/standards/verified-against.js +1 -1
- package/src/lib/tests-audit/audit.js +1 -1
- package/src/lib/text.js +5 -0
- package/src/scripts/setup-infra.js +22 -33
- package/src/utils/agents-installer.js +13 -30
- package/src/utils/claude-md-injector.js +16 -50
- package/src/utils/claude-settings-manager.js +2 -2
- package/src/utils/file-copier.js +3 -4
- package/src/utils/hooks-installer.js +55 -20
- package/src/utils/skills-installer.js +18 -78
- package/framework/templates/IDE-SNIPPETS.md +0 -262
- package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +0 -26
- package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +0 -28
- package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +0 -99
- package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +0 -40
- package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +0 -54
- package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +0 -53
- package/framework/templates/code/dotnet/contracts/README.md +0 -74
- package/framework/templates/code/dotnet/database/vector-entity.cs +0 -49
- package/framework/templates/code/sql/ai-agents/pgvector-embeddings-migration.sql.template +0 -91
- package/framework/templates/code/sql/postgresql-migration.template.sql +0 -108
- package/framework/templates/code/typescript/contracts.ts +0 -140
- package/framework/templates/examples/design-system-examples.md +0 -354
- package/framework/templates/infrastructure/docker/Dockerfile.template +0 -58
- package/framework/templates/infrastructure/github/actions/docker-build-push/action.yml.hbs +0 -45
- package/framework/templates/infrastructure/github/actions/health-check/action.yml.hbs +0 -27
- package/framework/templates/integrations/asaas-client.cs +0 -332
- package/framework/templates/integrations/asaas-webhook.cs +0 -290
- package/framework/templates/integrations/neon-auth-config.cs +0 -170
- package/framework/templates/ui/design-system.css +0 -226
- package/src/lib/detectors/index.js +0 -153
- package/src/lib/installers/templates-reconcile.js +0 -26
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
using System.Net.Http.Json;
|
|
2
|
-
using System.Text.Json.Serialization;
|
|
3
|
-
using Microsoft.Extensions.Logging;
|
|
4
|
-
using Microsoft.Extensions.Options;
|
|
5
|
-
|
|
6
|
-
namespace {{Namespace}}.Infrastructure.Services;
|
|
7
|
-
|
|
8
|
-
public class AsaasOptions
|
|
9
|
-
{
|
|
10
|
-
public const string SectionName = "Asaas";
|
|
11
|
-
|
|
12
|
-
// Produção: https://www.asaas.com/api/v3
|
|
13
|
-
public string BaseUrl { get; set; } = "https://sandbox.asaas.com/api/v3";
|
|
14
|
-
|
|
15
|
-
public string ApiKey { get; set; } = string.Empty;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public interface IAsaasClient
|
|
19
|
-
{
|
|
20
|
-
Task<AsaasCustomer> CreateCustomerAsync(CreateCustomerRequest request, CancellationToken ct = default);
|
|
21
|
-
Task<AsaasCustomer?> GetCustomerByIdAsync(string customerId, CancellationToken ct = default);
|
|
22
|
-
Task<AsaasCustomer?> GetCustomerByCpfCnpjAsync(string cpfCnpj, CancellationToken ct = default);
|
|
23
|
-
|
|
24
|
-
Task<AsaasPayment> CreatePaymentAsync(CreatePaymentRequest request, CancellationToken ct = default);
|
|
25
|
-
Task<AsaasPayment?> GetPaymentAsync(string paymentId, CancellationToken ct = default);
|
|
26
|
-
Task<AsaasPixQrCode?> GetPixQrCodeAsync(string paymentId, CancellationToken ct = default);
|
|
27
|
-
|
|
28
|
-
Task<AsaasSubscription> CreateSubscriptionAsync(CreateSubscriptionRequest request, CancellationToken ct = default);
|
|
29
|
-
Task<AsaasSubscription?> GetSubscriptionAsync(string subscriptionId, CancellationToken ct = default);
|
|
30
|
-
Task CancelSubscriptionAsync(string subscriptionId, CancellationToken ct = default);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public class AsaasClient : IAsaasClient
|
|
34
|
-
{
|
|
35
|
-
private readonly HttpClient _httpClient;
|
|
36
|
-
private readonly ILogger<AsaasClient> _logger;
|
|
37
|
-
|
|
38
|
-
public AsaasClient(HttpClient httpClient, ILogger<AsaasClient> logger)
|
|
39
|
-
{
|
|
40
|
-
_httpClient = httpClient;
|
|
41
|
-
_logger = logger;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public async Task<AsaasCustomer> CreateCustomerAsync(CreateCustomerRequest request, CancellationToken ct = default)
|
|
45
|
-
{
|
|
46
|
-
_logger.LogInformation("Creating Asaas customer: {Name}", request.Name);
|
|
47
|
-
|
|
48
|
-
var response = await _httpClient.PostAsJsonAsync("customers", request, ct);
|
|
49
|
-
await EnsureSuccessAsync(response, "create customer");
|
|
50
|
-
|
|
51
|
-
return await response.Content.ReadFromJsonAsync<AsaasCustomer>(ct)
|
|
52
|
-
?? throw new AsaasException("Failed to deserialize customer response");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public async Task<AsaasCustomer?> GetCustomerByIdAsync(string customerId, CancellationToken ct = default)
|
|
56
|
-
{
|
|
57
|
-
var response = await _httpClient.GetAsync($"customers/{customerId}", ct);
|
|
58
|
-
|
|
59
|
-
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
|
60
|
-
return null;
|
|
61
|
-
|
|
62
|
-
await EnsureSuccessAsync(response, "get customer");
|
|
63
|
-
return await response.Content.ReadFromJsonAsync<AsaasCustomer>(ct);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public async Task<AsaasCustomer?> GetCustomerByCpfCnpjAsync(string cpfCnpj, CancellationToken ct = default)
|
|
67
|
-
{
|
|
68
|
-
var response = await _httpClient.GetAsync($"customers?cpfCnpj={cpfCnpj}", ct);
|
|
69
|
-
await EnsureSuccessAsync(response, "search customer");
|
|
70
|
-
|
|
71
|
-
var result = await response.Content.ReadFromJsonAsync<AsaasListResponse<AsaasCustomer>>(ct);
|
|
72
|
-
return result?.Data?.FirstOrDefault();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public async Task<AsaasPayment> CreatePaymentAsync(CreatePaymentRequest request, CancellationToken ct = default)
|
|
76
|
-
{
|
|
77
|
-
_logger.LogInformation("Creating Asaas payment for customer {CustomerId}, type {BillingType}, value {Value}",
|
|
78
|
-
request.Customer, request.BillingType, request.Value);
|
|
79
|
-
|
|
80
|
-
var response = await _httpClient.PostAsJsonAsync("payments", request, ct);
|
|
81
|
-
await EnsureSuccessAsync(response, "create payment");
|
|
82
|
-
|
|
83
|
-
return await response.Content.ReadFromJsonAsync<AsaasPayment>(ct)
|
|
84
|
-
?? throw new AsaasException("Failed to deserialize payment response");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public async Task<AsaasPayment?> GetPaymentAsync(string paymentId, CancellationToken ct = default)
|
|
88
|
-
{
|
|
89
|
-
var response = await _httpClient.GetAsync($"payments/{paymentId}", ct);
|
|
90
|
-
|
|
91
|
-
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
|
92
|
-
return null;
|
|
93
|
-
|
|
94
|
-
await EnsureSuccessAsync(response, "get payment");
|
|
95
|
-
return await response.Content.ReadFromJsonAsync<AsaasPayment>(ct);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public async Task<AsaasPixQrCode?> GetPixQrCodeAsync(string paymentId, CancellationToken ct = default)
|
|
99
|
-
{
|
|
100
|
-
var response = await _httpClient.GetAsync($"payments/{paymentId}/pixQrCode", ct);
|
|
101
|
-
|
|
102
|
-
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
|
103
|
-
return null;
|
|
104
|
-
|
|
105
|
-
await EnsureSuccessAsync(response, "get pix qrcode");
|
|
106
|
-
return await response.Content.ReadFromJsonAsync<AsaasPixQrCode>(ct);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public async Task<AsaasSubscription> CreateSubscriptionAsync(CreateSubscriptionRequest request, CancellationToken ct = default)
|
|
110
|
-
{
|
|
111
|
-
_logger.LogInformation("Creating Asaas subscription for customer {CustomerId}", request.Customer);
|
|
112
|
-
|
|
113
|
-
var response = await _httpClient.PostAsJsonAsync("subscriptions", request, ct);
|
|
114
|
-
await EnsureSuccessAsync(response, "create subscription");
|
|
115
|
-
|
|
116
|
-
return await response.Content.ReadFromJsonAsync<AsaasSubscription>(ct)
|
|
117
|
-
?? throw new AsaasException("Failed to deserialize subscription response");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
public async Task<AsaasSubscription?> GetSubscriptionAsync(string subscriptionId, CancellationToken ct = default)
|
|
121
|
-
{
|
|
122
|
-
var response = await _httpClient.GetAsync($"subscriptions/{subscriptionId}", ct);
|
|
123
|
-
|
|
124
|
-
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
|
125
|
-
return null;
|
|
126
|
-
|
|
127
|
-
await EnsureSuccessAsync(response, "get subscription");
|
|
128
|
-
return await response.Content.ReadFromJsonAsync<AsaasSubscription>(ct);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public async Task CancelSubscriptionAsync(string subscriptionId, CancellationToken ct = default)
|
|
132
|
-
{
|
|
133
|
-
_logger.LogInformation("Canceling Asaas subscription {SubscriptionId}", subscriptionId);
|
|
134
|
-
|
|
135
|
-
var response = await _httpClient.DeleteAsync($"subscriptions/{subscriptionId}", ct);
|
|
136
|
-
await EnsureSuccessAsync(response, "cancel subscription");
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
private async Task EnsureSuccessAsync(HttpResponseMessage response, string operation)
|
|
140
|
-
{
|
|
141
|
-
if (!response.IsSuccessStatusCode)
|
|
142
|
-
{
|
|
143
|
-
var error = await response.Content.ReadAsStringAsync();
|
|
144
|
-
_logger.LogError("Asaas API error during {Operation}: {StatusCode} - {Error}",
|
|
145
|
-
operation, response.StatusCode, error);
|
|
146
|
-
throw new AsaasException($"Failed to {operation}: {response.StatusCode} - {error}");
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
public record CreateCustomerRequest
|
|
152
|
-
{
|
|
153
|
-
[JsonPropertyName("name")]
|
|
154
|
-
public required string Name { get; init; }
|
|
155
|
-
|
|
156
|
-
[JsonPropertyName("cpfCnpj")]
|
|
157
|
-
public required string CpfCnpj { get; init; }
|
|
158
|
-
|
|
159
|
-
[JsonPropertyName("email")]
|
|
160
|
-
public string? Email { get; init; }
|
|
161
|
-
|
|
162
|
-
[JsonPropertyName("phone")]
|
|
163
|
-
public string? Phone { get; init; }
|
|
164
|
-
|
|
165
|
-
[JsonPropertyName("mobilePhone")]
|
|
166
|
-
public string? MobilePhone { get; init; }
|
|
167
|
-
|
|
168
|
-
[JsonPropertyName("externalReference")]
|
|
169
|
-
public string? ExternalReference { get; init; }
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
public record CreatePaymentRequest
|
|
173
|
-
{
|
|
174
|
-
[JsonPropertyName("customer")]
|
|
175
|
-
public required string Customer { get; init; }
|
|
176
|
-
|
|
177
|
-
[JsonPropertyName("billingType")]
|
|
178
|
-
public required string BillingType { get; init; } // BOLETO, PIX, CREDIT_CARD
|
|
179
|
-
|
|
180
|
-
[JsonPropertyName("value")]
|
|
181
|
-
public required decimal Value { get; init; }
|
|
182
|
-
|
|
183
|
-
[JsonPropertyName("dueDate")]
|
|
184
|
-
public required string DueDate { get; init; } // yyyy-MM-dd
|
|
185
|
-
|
|
186
|
-
[JsonPropertyName("description")]
|
|
187
|
-
public string? Description { get; init; }
|
|
188
|
-
|
|
189
|
-
[JsonPropertyName("externalReference")]
|
|
190
|
-
public string? ExternalReference { get; init; }
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
public record CreateSubscriptionRequest
|
|
194
|
-
{
|
|
195
|
-
[JsonPropertyName("customer")]
|
|
196
|
-
public required string Customer { get; init; }
|
|
197
|
-
|
|
198
|
-
[JsonPropertyName("billingType")]
|
|
199
|
-
public required string BillingType { get; init; }
|
|
200
|
-
|
|
201
|
-
[JsonPropertyName("value")]
|
|
202
|
-
public required decimal Value { get; init; }
|
|
203
|
-
|
|
204
|
-
[JsonPropertyName("nextDueDate")]
|
|
205
|
-
public required string NextDueDate { get; init; }
|
|
206
|
-
|
|
207
|
-
[JsonPropertyName("cycle")]
|
|
208
|
-
public required string Cycle { get; init; } // MONTHLY, WEEKLY, BIWEEKLY, YEARLY
|
|
209
|
-
|
|
210
|
-
[JsonPropertyName("description")]
|
|
211
|
-
public string? Description { get; init; }
|
|
212
|
-
|
|
213
|
-
[JsonPropertyName("externalReference")]
|
|
214
|
-
public string? ExternalReference { get; init; }
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
public record AsaasCustomer
|
|
218
|
-
{
|
|
219
|
-
[JsonPropertyName("id")]
|
|
220
|
-
public string Id { get; init; } = string.Empty;
|
|
221
|
-
|
|
222
|
-
[JsonPropertyName("name")]
|
|
223
|
-
public string Name { get; init; } = string.Empty;
|
|
224
|
-
|
|
225
|
-
[JsonPropertyName("cpfCnpj")]
|
|
226
|
-
public string CpfCnpj { get; init; } = string.Empty;
|
|
227
|
-
|
|
228
|
-
[JsonPropertyName("email")]
|
|
229
|
-
public string? Email { get; init; }
|
|
230
|
-
|
|
231
|
-
[JsonPropertyName("externalReference")]
|
|
232
|
-
public string? ExternalReference { get; init; }
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
public record AsaasPayment
|
|
236
|
-
{
|
|
237
|
-
[JsonPropertyName("id")]
|
|
238
|
-
public string Id { get; init; } = string.Empty;
|
|
239
|
-
|
|
240
|
-
[JsonPropertyName("customer")]
|
|
241
|
-
public string Customer { get; init; } = string.Empty;
|
|
242
|
-
|
|
243
|
-
[JsonPropertyName("value")]
|
|
244
|
-
public decimal Value { get; init; }
|
|
245
|
-
|
|
246
|
-
[JsonPropertyName("status")]
|
|
247
|
-
public string Status { get; init; } = string.Empty;
|
|
248
|
-
|
|
249
|
-
[JsonPropertyName("billingType")]
|
|
250
|
-
public string BillingType { get; init; } = string.Empty;
|
|
251
|
-
|
|
252
|
-
[JsonPropertyName("dueDate")]
|
|
253
|
-
public string DueDate { get; init; } = string.Empty;
|
|
254
|
-
|
|
255
|
-
[JsonPropertyName("invoiceUrl")]
|
|
256
|
-
public string? InvoiceUrl { get; init; }
|
|
257
|
-
|
|
258
|
-
[JsonPropertyName("bankSlipUrl")]
|
|
259
|
-
public string? BankSlipUrl { get; init; }
|
|
260
|
-
|
|
261
|
-
[JsonPropertyName("externalReference")]
|
|
262
|
-
public string? ExternalReference { get; init; }
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
public record AsaasPixQrCode
|
|
266
|
-
{
|
|
267
|
-
[JsonPropertyName("encodedImage")]
|
|
268
|
-
public string? EncodedImage { get; init; }
|
|
269
|
-
|
|
270
|
-
[JsonPropertyName("payload")]
|
|
271
|
-
public string? Payload { get; init; }
|
|
272
|
-
|
|
273
|
-
[JsonPropertyName("expirationDate")]
|
|
274
|
-
public string? ExpirationDate { get; init; }
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
public record AsaasSubscription
|
|
278
|
-
{
|
|
279
|
-
[JsonPropertyName("id")]
|
|
280
|
-
public string Id { get; init; } = string.Empty;
|
|
281
|
-
|
|
282
|
-
[JsonPropertyName("customer")]
|
|
283
|
-
public string Customer { get; init; } = string.Empty;
|
|
284
|
-
|
|
285
|
-
[JsonPropertyName("value")]
|
|
286
|
-
public decimal Value { get; init; }
|
|
287
|
-
|
|
288
|
-
[JsonPropertyName("status")]
|
|
289
|
-
public string Status { get; init; } = string.Empty;
|
|
290
|
-
|
|
291
|
-
[JsonPropertyName("cycle")]
|
|
292
|
-
public string Cycle { get; init; } = string.Empty;
|
|
293
|
-
|
|
294
|
-
[JsonPropertyName("nextDueDate")]
|
|
295
|
-
public string NextDueDate { get; init; } = string.Empty;
|
|
296
|
-
|
|
297
|
-
[JsonPropertyName("externalReference")]
|
|
298
|
-
public string? ExternalReference { get; init; }
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
public record AsaasListResponse<T>
|
|
302
|
-
{
|
|
303
|
-
[JsonPropertyName("data")]
|
|
304
|
-
public List<T>? Data { get; init; }
|
|
305
|
-
|
|
306
|
-
[JsonPropertyName("totalCount")]
|
|
307
|
-
public int TotalCount { get; init; }
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
public class AsaasException : Exception
|
|
311
|
-
{
|
|
312
|
-
public AsaasException(string message) : base(message) { }
|
|
313
|
-
public AsaasException(string message, Exception innerException) : base(message, innerException) { }
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
public static class AsaasServiceExtensions
|
|
317
|
-
{
|
|
318
|
-
public static IServiceCollection AddAsaasClient(this IServiceCollection services, IConfiguration configuration)
|
|
319
|
-
{
|
|
320
|
-
services.Configure<AsaasOptions>(configuration.GetSection(AsaasOptions.SectionName));
|
|
321
|
-
|
|
322
|
-
services.AddHttpClient<IAsaasClient, AsaasClient>((sp, client) =>
|
|
323
|
-
{
|
|
324
|
-
var options = sp.GetRequiredService<IOptions<AsaasOptions>>().Value;
|
|
325
|
-
client.BaseAddress = new Uri(options.BaseUrl.TrimEnd('/') + "/");
|
|
326
|
-
client.DefaultRequestHeaders.Add("access_token", options.ApiKey);
|
|
327
|
-
client.DefaultRequestHeaders.Add("User-Agent", "MORPH-SPEC/1.0");
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
return services;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
using System.Text.Json.Serialization;
|
|
2
|
-
using Microsoft.AspNetCore.Mvc;
|
|
3
|
-
using Microsoft.Extensions.Logging;
|
|
4
|
-
|
|
5
|
-
namespace {{Namespace}}.Web.Controllers;
|
|
6
|
-
|
|
7
|
-
[ApiController]
|
|
8
|
-
[Route("api/webhooks/asaas")]
|
|
9
|
-
public class AsaasWebhookController : ControllerBase
|
|
10
|
-
{
|
|
11
|
-
private readonly IAsaasWebhookHandler _webhookHandler;
|
|
12
|
-
private readonly ILogger<AsaasWebhookController> _logger;
|
|
13
|
-
|
|
14
|
-
public AsaasWebhookController(
|
|
15
|
-
IAsaasWebhookHandler webhookHandler,
|
|
16
|
-
ILogger<AsaasWebhookController> logger)
|
|
17
|
-
{
|
|
18
|
-
_webhookHandler = webhookHandler;
|
|
19
|
-
_logger = logger;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
[HttpPost]
|
|
23
|
-
public async Task<IActionResult> HandleWebhook([FromBody] AsaasWebhookPayload payload)
|
|
24
|
-
{
|
|
25
|
-
_logger.LogInformation("Received Asaas webhook: {Event}", payload.Event);
|
|
26
|
-
|
|
27
|
-
try
|
|
28
|
-
{
|
|
29
|
-
await _webhookHandler.HandleAsync(payload);
|
|
30
|
-
return Ok();
|
|
31
|
-
}
|
|
32
|
-
catch (Exception ex)
|
|
33
|
-
{
|
|
34
|
-
_logger.LogError(ex, "Error processing Asaas webhook: {Event}", payload.Event);
|
|
35
|
-
// 200 mesmo na falha: o Asaas reenvia toda resposta não-2xx, e o erro já está no log.
|
|
36
|
-
return Ok();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public interface IAsaasWebhookHandler
|
|
42
|
-
{
|
|
43
|
-
Task HandleAsync(AsaasWebhookPayload payload, CancellationToken ct = default);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public class AsaasWebhookHandler : IAsaasWebhookHandler
|
|
47
|
-
{
|
|
48
|
-
private readonly IPaymentService _paymentService;
|
|
49
|
-
private readonly ISubscriptionService _subscriptionService;
|
|
50
|
-
private readonly ILogger<AsaasWebhookHandler> _logger;
|
|
51
|
-
|
|
52
|
-
public AsaasWebhookHandler(
|
|
53
|
-
IPaymentService paymentService,
|
|
54
|
-
ISubscriptionService subscriptionService,
|
|
55
|
-
ILogger<AsaasWebhookHandler> logger)
|
|
56
|
-
{
|
|
57
|
-
_paymentService = paymentService;
|
|
58
|
-
_subscriptionService = subscriptionService;
|
|
59
|
-
_logger = logger;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public async Task HandleAsync(AsaasWebhookPayload payload, CancellationToken ct = default)
|
|
63
|
-
{
|
|
64
|
-
_logger.LogInformation("Processing Asaas webhook: {Event} for {PaymentId}",
|
|
65
|
-
payload.Event, payload.Payment?.Id ?? "N/A");
|
|
66
|
-
|
|
67
|
-
switch (payload.Event)
|
|
68
|
-
{
|
|
69
|
-
case AsaasWebhookEvents.PaymentCreated:
|
|
70
|
-
await HandlePaymentCreatedAsync(payload, ct);
|
|
71
|
-
break;
|
|
72
|
-
|
|
73
|
-
case AsaasWebhookEvents.PaymentAwaitingRiskAnalysis:
|
|
74
|
-
await HandlePaymentAwaitingRiskAsync(payload, ct);
|
|
75
|
-
break;
|
|
76
|
-
|
|
77
|
-
case AsaasWebhookEvents.PaymentPending:
|
|
78
|
-
await HandlePaymentPendingAsync(payload, ct);
|
|
79
|
-
break;
|
|
80
|
-
|
|
81
|
-
case AsaasWebhookEvents.PaymentConfirmed:
|
|
82
|
-
case AsaasWebhookEvents.PaymentReceived:
|
|
83
|
-
await HandlePaymentConfirmedAsync(payload, ct);
|
|
84
|
-
break;
|
|
85
|
-
|
|
86
|
-
case AsaasWebhookEvents.PaymentOverdue:
|
|
87
|
-
await HandlePaymentOverdueAsync(payload, ct);
|
|
88
|
-
break;
|
|
89
|
-
|
|
90
|
-
case AsaasWebhookEvents.PaymentRefunded:
|
|
91
|
-
case AsaasWebhookEvents.PaymentRefundInProgress:
|
|
92
|
-
await HandlePaymentRefundedAsync(payload, ct);
|
|
93
|
-
break;
|
|
94
|
-
|
|
95
|
-
case AsaasWebhookEvents.PaymentChargebackRequested:
|
|
96
|
-
case AsaasWebhookEvents.PaymentChargebackDispute:
|
|
97
|
-
await HandlePaymentChargebackAsync(payload, ct);
|
|
98
|
-
break;
|
|
99
|
-
|
|
100
|
-
case AsaasWebhookEvents.PaymentDeleted:
|
|
101
|
-
await HandlePaymentDeletedAsync(payload, ct);
|
|
102
|
-
break;
|
|
103
|
-
|
|
104
|
-
case AsaasWebhookEvents.SubscriptionCreated:
|
|
105
|
-
await HandleSubscriptionCreatedAsync(payload, ct);
|
|
106
|
-
break;
|
|
107
|
-
|
|
108
|
-
case AsaasWebhookEvents.SubscriptionUpdated:
|
|
109
|
-
await HandleSubscriptionUpdatedAsync(payload, ct);
|
|
110
|
-
break;
|
|
111
|
-
|
|
112
|
-
case AsaasWebhookEvents.SubscriptionDeleted:
|
|
113
|
-
await HandleSubscriptionDeletedAsync(payload, ct);
|
|
114
|
-
break;
|
|
115
|
-
|
|
116
|
-
default:
|
|
117
|
-
_logger.LogWarning("Unhandled Asaas webhook event: {Event}", payload.Event);
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
private async Task HandlePaymentCreatedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
123
|
-
{
|
|
124
|
-
if (payload.Payment is null) return;
|
|
125
|
-
|
|
126
|
-
_logger.LogInformation("Payment created: {PaymentId}", payload.Payment.Id);
|
|
127
|
-
await _paymentService.SyncPaymentAsync(payload.Payment.Id, ct);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private async Task HandlePaymentAwaitingRiskAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
131
|
-
{
|
|
132
|
-
if (payload.Payment is null) return;
|
|
133
|
-
|
|
134
|
-
_logger.LogInformation("Payment awaiting risk analysis: {PaymentId}", payload.Payment.Id);
|
|
135
|
-
await _paymentService.UpdateStatusAsync(payload.Payment.Id, PaymentStatus.AwaitingRisk, ct);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private async Task HandlePaymentPendingAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
139
|
-
{
|
|
140
|
-
if (payload.Payment is null) return;
|
|
141
|
-
|
|
142
|
-
_logger.LogInformation("Payment pending: {PaymentId}", payload.Payment.Id);
|
|
143
|
-
await _paymentService.UpdateStatusAsync(payload.Payment.Id, PaymentStatus.Pending, ct);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
private async Task HandlePaymentConfirmedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
147
|
-
{
|
|
148
|
-
if (payload.Payment is null) return;
|
|
149
|
-
|
|
150
|
-
_logger.LogInformation("Payment confirmed: {PaymentId}, Value: {Value}",
|
|
151
|
-
payload.Payment.Id, payload.Payment.Value);
|
|
152
|
-
|
|
153
|
-
await _paymentService.ConfirmPaymentAsync(payload.Payment.Id, ct);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
private async Task HandlePaymentOverdueAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
157
|
-
{
|
|
158
|
-
if (payload.Payment is null) return;
|
|
159
|
-
|
|
160
|
-
_logger.LogWarning("Payment overdue: {PaymentId}", payload.Payment.Id);
|
|
161
|
-
await _paymentService.MarkOverdueAsync(payload.Payment.Id, ct);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private async Task HandlePaymentRefundedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
165
|
-
{
|
|
166
|
-
if (payload.Payment is null) return;
|
|
167
|
-
|
|
168
|
-
_logger.LogInformation("Payment refunded: {PaymentId}", payload.Payment.Id);
|
|
169
|
-
await _paymentService.RefundPaymentAsync(payload.Payment.Id, ct);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private async Task HandlePaymentChargebackAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
173
|
-
{
|
|
174
|
-
if (payload.Payment is null) return;
|
|
175
|
-
|
|
176
|
-
_logger.LogWarning("Payment chargeback: {PaymentId}", payload.Payment.Id);
|
|
177
|
-
await _paymentService.HandleChargebackAsync(payload.Payment.Id, ct);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
private async Task HandlePaymentDeletedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
181
|
-
{
|
|
182
|
-
if (payload.Payment is null) return;
|
|
183
|
-
|
|
184
|
-
_logger.LogInformation("Payment deleted: {PaymentId}", payload.Payment.Id);
|
|
185
|
-
await _paymentService.DeletePaymentAsync(payload.Payment.Id, ct);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
private async Task HandleSubscriptionCreatedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
189
|
-
{
|
|
190
|
-
_logger.LogInformation("Subscription created via webhook");
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
private async Task HandleSubscriptionUpdatedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
194
|
-
{
|
|
195
|
-
_logger.LogInformation("Subscription updated via webhook");
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private async Task HandleSubscriptionDeletedAsync(AsaasWebhookPayload payload, CancellationToken ct)
|
|
199
|
-
{
|
|
200
|
-
_logger.LogInformation("Subscription deleted via webhook");
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
public static class AsaasWebhookEvents
|
|
205
|
-
{
|
|
206
|
-
public const string PaymentCreated = "PAYMENT_CREATED";
|
|
207
|
-
public const string PaymentAwaitingRiskAnalysis = "PAYMENT_AWAITING_RISK_ANALYSIS";
|
|
208
|
-
public const string PaymentPending = "PAYMENT_PENDING";
|
|
209
|
-
public const string PaymentConfirmed = "PAYMENT_CONFIRMED";
|
|
210
|
-
public const string PaymentReceived = "PAYMENT_RECEIVED";
|
|
211
|
-
public const string PaymentOverdue = "PAYMENT_OVERDUE";
|
|
212
|
-
public const string PaymentRefunded = "PAYMENT_REFUNDED";
|
|
213
|
-
public const string PaymentRefundInProgress = "PAYMENT_REFUND_IN_PROGRESS";
|
|
214
|
-
public const string PaymentChargebackRequested = "PAYMENT_CHARGEBACK_REQUESTED";
|
|
215
|
-
public const string PaymentChargebackDispute = "PAYMENT_CHARGEBACK_DISPUTE";
|
|
216
|
-
public const string PaymentDeleted = "PAYMENT_DELETED";
|
|
217
|
-
|
|
218
|
-
public const string SubscriptionCreated = "SUBSCRIPTION_CREATED";
|
|
219
|
-
public const string SubscriptionUpdated = "SUBSCRIPTION_UPDATED";
|
|
220
|
-
public const string SubscriptionDeleted = "SUBSCRIPTION_DELETED";
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
public record AsaasWebhookPayload
|
|
224
|
-
{
|
|
225
|
-
[JsonPropertyName("event")]
|
|
226
|
-
public string Event { get; init; } = string.Empty;
|
|
227
|
-
|
|
228
|
-
[JsonPropertyName("payment")]
|
|
229
|
-
public AsaasWebhookPayment? Payment { get; init; }
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
public record AsaasWebhookPayment
|
|
233
|
-
{
|
|
234
|
-
[JsonPropertyName("id")]
|
|
235
|
-
public string Id { get; init; } = string.Empty;
|
|
236
|
-
|
|
237
|
-
[JsonPropertyName("customer")]
|
|
238
|
-
public string Customer { get; init; } = string.Empty;
|
|
239
|
-
|
|
240
|
-
[JsonPropertyName("value")]
|
|
241
|
-
public decimal Value { get; init; }
|
|
242
|
-
|
|
243
|
-
[JsonPropertyName("status")]
|
|
244
|
-
public string Status { get; init; } = string.Empty;
|
|
245
|
-
|
|
246
|
-
[JsonPropertyName("billingType")]
|
|
247
|
-
public string BillingType { get; init; } = string.Empty;
|
|
248
|
-
|
|
249
|
-
[JsonPropertyName("externalReference")]
|
|
250
|
-
public string? ExternalReference { get; init; }
|
|
251
|
-
|
|
252
|
-
[JsonPropertyName("subscription")]
|
|
253
|
-
public string? Subscription { get; init; }
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
public enum PaymentStatus
|
|
257
|
-
{
|
|
258
|
-
Pending,
|
|
259
|
-
AwaitingRisk,
|
|
260
|
-
Confirmed,
|
|
261
|
-
Received,
|
|
262
|
-
Overdue,
|
|
263
|
-
Refunded,
|
|
264
|
-
Chargeback,
|
|
265
|
-
Deleted
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
public interface IPaymentService
|
|
269
|
-
{
|
|
270
|
-
Task SyncPaymentAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
271
|
-
Task UpdateStatusAsync(string asaasPaymentId, PaymentStatus status, CancellationToken ct = default);
|
|
272
|
-
Task ConfirmPaymentAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
273
|
-
Task MarkOverdueAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
274
|
-
Task RefundPaymentAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
275
|
-
Task HandleChargebackAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
276
|
-
Task DeletePaymentAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
public interface ISubscriptionService
|
|
280
|
-
{
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
public static class AsaasWebhookServiceExtensions
|
|
284
|
-
{
|
|
285
|
-
public static IServiceCollection AddAsaasWebhook(this IServiceCollection services)
|
|
286
|
-
{
|
|
287
|
-
services.AddScoped<IAsaasWebhookHandler, AsaasWebhookHandler>();
|
|
288
|
-
return services;
|
|
289
|
-
}
|
|
290
|
-
}
|