├── .gitattributes ├── .github └── workflows │ └── deploy.yml ├── .gitignore ├── CHANGELOG.md ├── Constants ├── InvoiceRelation.cs ├── InvoiceType.cs ├── InvoiceUse.cs ├── PaymentForm.cs ├── PaymentMethod.cs ├── TaxSystem.cs ├── TaxType.cs ├── Taxability.cs └── WebhookEvents.cs ├── FacturAPIException.cs ├── FacturapiClient.cs ├── LICENSE ├── Models ├── Address.cs ├── CatalogItem.cs ├── Certificate.cs ├── CompletionStep.cs ├── Customer.cs ├── Customization.cs ├── Global.cs ├── Invoice.cs ├── InvoiceItem.cs ├── Legal.cs ├── LiveApiKey.cs ├── Organization.cs ├── Payment.cs ├── PdfExtra.cs ├── Product.cs ├── Receipt.cs ├── Retention.cs ├── SearchResult.cs ├── SeriesGroup.cs ├── Stamp.cs ├── Tax.cs ├── TaxIdValidation.cs ├── TaxInfoValidation.cs ├── Webhook.cs └── WebhookValidateSignature.cs ├── README.md ├── Router ├── CatalogRouter.cs ├── CustomerRouter.cs ├── InvoiceRouter.cs ├── OrganizationRouter.cs ├── ProductRouter.cs ├── ReceiptRouter.cs ├── RetentionRouter.cs ├── Router.cs ├── ToolRouter.cs └── WebhookRouter.cs ├── Util └── SnakeCasePropertyNamesContractResolver.cs ├── Wrappers ├── BaseWrapper.cs ├── CatalogWrapper.cs ├── CustomerWrapper.cs ├── InvoiceWrapper.cs ├── OrganizationWrapper.cs ├── ProductWrapper.cs ├── ReceiptWrapper.cs ├── RetentionWrapper.cs ├── ToolWrapper.cs └── WebhookWrapper.cs ├── facturapi-net.csproj ├── facturapi-net.sln ├── facturapi.ico └── icon.png /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy to NuGet 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | deploy: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout code 14 | uses: actions/checkout@v4 15 | 16 | - name: Setup .NET 17 | uses: actions/setup-dotnet@v4 18 | with: 19 | dotnet-version: '8.0.x' # Adjust the .NET version as needed 20 | 21 | - name: Restore dependencies 22 | run: dotnet restore 23 | 24 | - name: Build 25 | run: dotnet build --configuration Release --no-restore 26 | 27 | - name: Pack 28 | run: dotnet pack --configuration Release --no-build --output ./nupkg 29 | 30 | - name: Install xmllint 31 | run: sudo apt-get update && sudo apt-get install -y libxml2-utils 32 | 33 | - name: Check if version exists on NuGet 34 | id: version-check 35 | run: | 36 | PACKAGE_ID="Facturapi" 37 | VERSION=$(xmllint --xpath "string(//Project/PropertyGroup/Version)" facturapi-net.csproj) 38 | echo "Detected version: $VERSION" 39 | echo "version=$VERSION" >> $GITHUB_OUTPUT 40 | if curl -sSf "https://api.nuget.org/v3-flatcontainer/${PACKAGE_ID,,}/$VERSION/${PACKAGE_ID,,}.$VERSION.nupkg" > /dev/null; then 41 | echo "Version $VERSION already exists. Skipping push." 42 | echo "exists=true" >> $GITHUB_OUTPUT 43 | else 44 | echo "Version $VERSION does not exist. Proceeding with publish." 45 | echo "exists=false" >> $GITHUB_OUTPUT 46 | fi 47 | 48 | - name: Publish to NuGet 49 | if: steps.version-check.outputs.exists == 'false' 50 | run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [4.8.0] - 2025-04-22 9 | 10 | ### Added 11 | 12 | - Add Create Webhook `Webhooks.CreateAsync` 13 | - Add Update Webhook `Webhooks.UpdateAsync` 14 | - Add Retrieve Webhook `Webhooks.RetrieveAsync` 15 | - Add Delete Webhook `Webhooks.DeleteAsync` 16 | - Add List Webhooks `Webhooks.ListAsync` 17 | - Add Validate Signature Webhook `Webhooks.ValidateSignatureAsync` 18 | 19 | ## [4.7.1] - 2025-04-16 20 | 21 | ### Added 22 | 23 | - Type IepsMode for Tax model 24 | - Type Factor for Tax model 25 | 26 | ## [4.7.0] = 2025-02-25 27 | 28 | ### Added 29 | 30 | - Support sending query params to `Customers.CreateAsync` and `Customers.UpdateAsync` methods. 31 | - Added fields to `Customer` model: `SatValidatedAt`, `EditLink` and `EditLinkExpiresAt`. 32 | - Added targets for .NET 6.0 and .NET 7.0. 33 | 34 | ## [4.6.0] - 2024-09-23 35 | 36 | ### Added 37 | 38 | - Add List of Live Api Keys `Organizations.ListAsyncLiveApiKey` 39 | - Add Delete of a Live Api Key `Organization.DeleteAsyncLiveApiKey` 40 | 41 | 42 | ## [4.5.0] - 2024-05-06 43 | 44 | ### Added 45 | 46 | - New methods to manage Series: `Organizations.ListSeriesGroupAsync`, `Organizations.CreateSeriesGroupAsync`, `Organizations.UpdateSeriesGroupAsync`, `Organizations.DeleteSeriesGroupAsync`. 47 | 48 | ## [4.4.0] - 2024-05-27 49 | 50 | ### Added 51 | 52 | - New methods for invoice drafts: `Invoices.UpdateStatusAsync`, `Invoices.UpdateDraftAsync`, `Invoices.StampDraftAsync` and `Invoices.CopyToDraftAsync`. 53 | 54 | ## [4.3.0] - 2024-04-17 55 | 56 | ### Added 57 | 58 | - Global constants of taxability 59 | - Taxability type in product type 60 | 61 | ## [4.2.0] - 2024-03-12 62 | 63 | ### Added 64 | 65 | - Global types in invoice model 66 | - Update invoice uses constants 67 | - Update payment form constants 68 | - Add new method for delete certs in organization 69 | 70 | 71 | ## [4.1.0] - 2023-12-06 72 | 73 | ### Added 74 | 75 | - Support for more .NET versions: .NET Core, .NET 6 and .NET 4.5.2 76 | - Allow passing options object to invoice creation 77 | 78 | ## [4.0.0] - 2023-12-05 79 | 80 | ### Breaking changes 81 | 82 | - We now target .NET standard 2.0 instead of .NET framework 4.5. 83 | 84 | ### Added 85 | 86 | - RESICO Tax system 87 | - Download cancellation receipt XML and PDF 88 | 89 | ## [3.2.0] - 2023-07-12 90 | 91 | ### Added 92 | 93 | - Download receipt PDF 94 | - Send receipt by email 95 | 96 | ## [3.1.0] - 2022-03-14 97 | 98 | ### Added 99 | 100 | - Tax Validation endpoint 101 | - Customer `TaxSystem` property 102 | - Invoice `Address` property 103 | 104 | ## [3.0.0] - 2022-01-31 105 | 106 | - Added support for CFDI 4.0 107 | 108 | ## [2.1.1] - 2021-09-03 109 | 110 | ### Fixed 111 | 112 | - Unit keys catalog was pointing to product keys catalog 113 | 114 | ## [2.1.0] - 2021-08-06 115 | 116 | ### Added 117 | 118 | - Catalogs API 119 | - Endpoint for validating tax id 120 | 121 | ## [2.0.1] - 2021-07-28 122 | 123 | ### Added 124 | 125 | - Missing property on Stamp object: ComplementString 126 | 127 | ## [2.0.0] - 2021-04-19 128 | 129 | ### Breaking changes 130 | 131 | - Removed deprecated property `Invoice.ForeignTrade`. 132 | - Removed deprecated `Wrapper` class. 133 | 134 | ### Added 135 | 136 | - Support for Receipts API 137 | - Support for Retentions API 138 | - Added missing properties on `Invoice` class: `ExternalId`, `Type`, `Stamp` and `Complements`. 139 | 140 | ## [1.0.3] - 2020-08-19 141 | ### Fixed 142 | 143 | - `Invoice.Payments[].Related` should be a List 144 | 145 | ## [1.0.2] - 2019-09-12 146 | ### Fixed 147 | 148 | - Bug at uploading certificates. 149 | 150 | ## [1.0.1] - 2019-08-25 151 | ### Fixed 152 | 153 | - Problem uploading logo and certs for an organization. 154 | 155 | ## [1.0.0] - 2019-02-21 156 | ### Added 157 | 158 | - Bunch of properties missing from the Invoice class like Payments, ForeignTrade, Related, etc. 159 | - `TotalResults` property in search results. 160 | - `FacturapiClient` replaces `Wrapper` and is now the preferred way of instanciating the API client. Usage is exactly the same. Actually this is more a renaming than a replacement. 161 | - Now you can send parameters to the `Invoice.SendByEmail` method, which means you can specify the email address to send the invoice to. 162 | 163 | ### Deprecated 164 | 165 | - Wrapper class. We're replacing it with the more descriptive `FacturapiClient`. `Wrapper` will be available during this version for keeping backwards compatibility, but will be removed in the next major release. 166 | 167 | ### Removed 168 | 169 | - Deprecated static methods. 170 | -------------------------------------------------------------------------------- /Constants/InvoiceRelation.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public static class InvoiceRelation 4 | { 5 | public const string NOTA_DE_CREDITO = "01"; 6 | public const string NOTA_DE_DEBITO = "02"; 7 | public const string DEVOLUCION_DE_MERCANCIA = "03"; 8 | public const string SUSTITUCION_DE_CFDI = "04"; 9 | public const string TRASLADOS_DE_MERCANCIAS_FACTURADOS = "05"; 10 | public const string FACTURA_GENERADA_POR_TRASLADOS = "06"; 11 | public const string CFDI_POR_APLICACION_DE_ANTICIPO = "07"; 12 | public const string FACTURA_POR_PAGOS_EN_PARCIALIDADES = "08"; 13 | public const string FACTURA_POR_PAGOS_DIFERIDOS = "09"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Constants/InvoiceType.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public static class InvoiceType 4 | { 5 | public const string INGRESO = "I"; 6 | public const string EGRESO = "E"; 7 | public const string TRASLADO = "T"; 8 | public const string NOMINA = "N"; 9 | public const string PAGO = "P"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Constants/InvoiceUse.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public static class InvoiceUse 4 | { 5 | public const string ADQUISICION_MERCANCIAS = "G01"; 6 | public const string DEVOLUCIONES_DESCUENTOS_BONIFICACIONES = "G02"; 7 | public const string GASTOS_EN_GENERAL = "G03"; 8 | public const string CONSTRUCCIONES = "I01"; 9 | public const string MOBILIARIO_Y_EQUIPO_DE_OFICINA = "I02"; 10 | public const string EQUIPO_DE_TRANSPORTE = "I03"; 11 | public const string EQUIPO_DE_COMPUTO = "I04"; 12 | public const string DADOS_TROQUELES_HERRAMENTAL = "I05"; 13 | public const string COMUNICACIONES_TELEFONICAS = "I06"; 14 | public const string COMUNICACIONES_SATELITALES = "I07"; 15 | public const string OTRA_MAQUINARIA = "I08"; 16 | public const string HONORARIOS_MEDICOS = "D01"; 17 | public const string GASTOS_MEDICOS_POR_INCAPACIDAD = "D02"; 18 | public const string GASTOS_FUNERALES = "D03"; 19 | public const string DONATIVOS = "D04"; 20 | public const string INTERESES_POR_CREDITOS_HIPOTECARIOS = "D05"; 21 | public const string APORTACIONES_VOLUNTARIAS_SAR = "D06"; 22 | public const string PRIMA_SEGUROS_GASTOS_MEDICOS = "D07"; 23 | public const string GASTOS_TRANSPORTACION_ESCOLAR = "D08"; 24 | public const string CUENTAS_AHORRO_PENSIONES = "D09"; 25 | public const string SERVICIOS_EDUCATIVOS = "D10"; 26 | public const string SIN_EFECTOS_FISCALES = "S01"; 27 | public const string PAGOS = "CP01"; 28 | public const string NOMINA = "CN01"; 29 | public const string POR_DEFINIR = "P01"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Constants/PaymentForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facturapi 8 | { 9 | public static class PaymentForm 10 | { 11 | public const string EFECTIVO = "01"; 12 | public const string CHEQUE_NOMINATIVO = "02"; 13 | public const string TRANSFERENCIA_ELECTRONICA = "03"; 14 | public const string TARJETA_DE_CREDITO = "04"; 15 | public const string MONEDERO_ELECTRONICO = "05"; 16 | public const string DINERO_ELECTRONICO = "06"; 17 | public const string VALES_DE_DESPENSA = "08"; 18 | public const string DACION_EN_PAGO = "12"; 19 | public const string SUBROGACION = "13"; 20 | public const string CONSIGNACION = "14"; 21 | public const string CONDONACION = "15"; 22 | public const string COMPENSACION = "17"; 23 | public const string NOVACION = "23"; 24 | public const string CONFUSION = "24"; 25 | public const string REMISION_DE_DEUDA = "25"; 26 | public const string PRESCRIPCION_O_CADUCIDAD = "26"; 27 | public const string A_SATISFACCION_DEL_ACREEDOR = "27"; 28 | public const string TARJETA_DE_DEBITO = "28"; 29 | public const string TERJETA_DE_SERVICIOS = "29"; 30 | public const string APLICACION_ANTICIPOS = "30"; 31 | public const string INTERMEDIARIO_PAGOS = "31"; 32 | public const string POR_DEFINIR = "99"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Constants/PaymentMethod.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public static class PaymentMethod 4 | { 5 | public const string PAGO_EN_UNA_SOLA_EXHIBICION = "PUE"; 6 | public const string PAGO_EN_PARCIALIDADES_O_DIFERIDO = "PPD"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Constants/TaxSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facturapi 8 | { 9 | public static class TaxSystem 10 | { 11 | public const string GENERAL_LEY_DE_PERSONAS_MORALES = "601"; 12 | public const string PERSONAS_MORALES_CON_FINES_NO_LUCRATIVOS = "603"; 13 | public const string SUELDOS_Y_SALARIOS = "605"; 14 | public const string ARRENDAMIENTO = "606"; 15 | public const string DEMAS_INGRESOS = "608"; 16 | public const string CONSOLIDACION = "609"; 17 | public const string RESIDENTES_EN_EL_EXTRANJERO = "610"; 18 | public const string INGRESOS_POR_DIVIDENDOS_SOCIOS_Y_ACCIONISTAS = "611"; 19 | public const string PERSONAS_FISICAS_CON_ACTIVIDADES_EMPRESARIALES_Y_PROFESIONALES = "612"; 20 | public const string INGRESOS_POR_INTERESES = "614"; 21 | public const string SIN_OBLIGACIONES_FISCALES = "616"; 22 | public const string SOCIEDADES_COOPERATIVAS_DE_PRODUCCION = "620"; 23 | public const string REGIMEN_DE_INCORPORACION_FISCAL = "621"; 24 | public const string ACTIVIDADES_AGRICOLAS_GANADERAS_SILVICOLAS_Y_PESQUERAS = "622"; 25 | public const string OPCIONAL_PARA_GRUPOS_DE_SOCIEDADES = "623"; 26 | public const string COORDINADOS = "624"; 27 | public const string RESICO = "626"; 28 | public const string HIDROCARBUROS = "628"; 29 | public const string REGIMEN_DE_ENAJENACION_O_ADQUISICION_DE_BIENES = "607"; 30 | public const string PREFERENTES_Y_EMPRESAS_MULTINACIONALES = "629"; 31 | public const string ENAJENACION_DE_ACCIONES_EN_BOLSA_DE_VALORES = "630"; 32 | public const string REGIMEN_DE_LOS_INGRESOS_POR_OBTENCION_DE_PREMIOS = "615"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Constants/TaxType.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public static class TaxType 4 | { 5 | public const string IVA = "IVA"; 6 | public const string IEPS = "IEPS"; 7 | public const string ISR = "ISR"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Constants/Taxability.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public static class Taxability 4 | { 5 | public const string NO = "01"; 6 | public const string SI = "02"; 7 | public const string SI_Y_NO_OBLIGADO_A_DESGLOSE = "03"; 8 | public const string SI_Y_NO_CAUSA_IMPUESTO = "04"; 9 | public const string PODEBI = "05"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Constants/WebhookEvents.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public static class WebhooksEvents 4 | { 5 | public const string GLOBAL_INVOICE_CREATED = "invoice.global_invoice_created"; 6 | public const string INVOICE_STATUS_UPDATED = "invoice.status_updated"; 7 | public const string INVOICE_CANCELLATION_STATUS_UPDATED = "invoice.cancellation_status_updated"; 8 | public const string INVOICES_CREATED_FROM_DASHBOARD = "invoice.created_from_dashboard"; 9 | public const string RECEIPT_SELF_INVOICE_COMPLETE = "receipt.self_invoice_complete"; 10 | public const string RECEIPT_STATUS_UPDATED = "receipt.status_updated"; 11 | public const string CUSTOMER_EDIT_LINK_COMPLETED = "customer.edit_link_completed"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /FacturAPIException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facturapi 8 | { 9 | public class FacturapiException : Exception 10 | { 11 | public FacturapiException() : base() { } 12 | public FacturapiException(string message) : base(message) { } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /FacturapiClient.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public class FacturapiClient 4 | { 5 | public Wrappers.CustomerWrapper Customer { get; private set; } 6 | public Wrappers.ProductWrapper Product { get; private set; } 7 | public Wrappers.InvoiceWrapper Invoice { get; private set; } 8 | public Wrappers.OrganizationWrapper Organization { get; private set; } 9 | public Wrappers.ReceiptWrapper Receipt { get; private set; } 10 | public Wrappers.RetentionWrapper Retention { get; private set; } 11 | public Wrappers.CatalogWrapper Catalog { get; private set; } 12 | public Wrappers.ToolWrapper Tool { get; private set; } 13 | 14 | public FacturapiClient(string apiKey, string apiVersion = "v2") 15 | { 16 | this.Customer = new Wrappers.CustomerWrapper(apiKey, apiVersion); 17 | this.Product = new Wrappers.ProductWrapper(apiKey, apiVersion); 18 | this.Invoice = new Wrappers.InvoiceWrapper(apiKey, apiVersion); 19 | this.Organization = new Wrappers.OrganizationWrapper(apiKey, apiVersion); 20 | this.Receipt = new Wrappers.ReceiptWrapper(apiKey, apiVersion); 21 | this.Retention = new Wrappers.RetentionWrapper(apiKey, apiVersion); 22 | this.Catalog = new Wrappers.CatalogWrapper(apiKey, apiVersion); 23 | this.Tool = new Wrappers.ToolWrapper(apiKey, apiVersion); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Javier Rosas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Models/Address.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public class Address 4 | { 5 | public string Street { get; set; } 6 | public string Exterior { get; set; } 7 | public string Interior { get; set; } 8 | public string Neighborhood { get; set; } 9 | public string City { get; set; } 10 | public string Municipality { get; set; } 11 | public string State { get; set; } 12 | public string Country { get; set; } 13 | public string Zip { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Models/CatalogItem.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public class CatalogItem 4 | { 5 | public string Key { get; set; } 6 | public string Description { get; set; } 7 | public double Score { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Models/Certificate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facturapi 4 | { 5 | public class Certificate 6 | { 7 | public DateTime UpdatedAt { get; set; } 8 | public DateTime ExpiresAt { get; set; } 9 | public bool HasCertificate { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Models/CompletionStep.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public class CompletionStep 4 | { 5 | public string Type { get; set; } 6 | public string Description { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Models/Customer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facturapi 4 | { 5 | public class Customer 6 | { 7 | public string Id { get; set; } 8 | public DateTime CreatedAt { get; set; } 9 | public bool Livemode { get; set; } 10 | public string Email { get; set; } 11 | public string Phone { get; set; } 12 | public Address Address { get; set; } 13 | public string LegalName { get; set; } 14 | public string TaxId { get; set; } 15 | public string TaxSystem { get; set; } 16 | public DateTime SatValidatedAt { get; set; } 17 | public string EditLink { get; set; } 18 | public DateTime EditLinkExpiresAt { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Models/Customization.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public class Customization 4 | { 5 | public string Color { get; set; } 6 | public bool HasLogo { get; set; } 7 | public PdfExtra PdfExtra { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Models/Global.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | public class Global 7 | { 8 | public string Periodicity { get; set; } 9 | public string Months { get; set; } 10 | public int Year { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Models/Invoice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | public class Invoice 7 | { 8 | public string Id { get; set; } 9 | public string ExternalId { get; set; } 10 | public DateTime CreatedAt { get; set; } 11 | public bool Livemode { get; set; } 12 | public string Status { get; set; } 13 | public string Type { get; set; } 14 | public string VerificationUrl { get; set; } 15 | public string CancellationStatus { get; set; } 16 | public DateTime Date { get; set; } 17 | public Address Address { get; set; } 18 | public Customer Customer { get; set; } 19 | public decimal Total { get; set; } 20 | public string Uuid { get; set; } 21 | public string FolioNumber { get; set; } 22 | public string Series { get; set; } 23 | public string Use { get; set; } 24 | public string PaymentForm { get; set; } 25 | public string PaymentMethod { get; set; } 26 | public string Currecy { get; set; } 27 | public decimal Exchange { get; set; } 28 | public string CancellationReceipt { get; set; } 29 | public List Related { get; set; } 30 | public string Relation { get; set; } 31 | public string Conditions { get; set; } 32 | public List Items { get; set; } 33 | public List Payments { get; set; } 34 | public List Namespaces { get; set; } 35 | public Stamp Stamp { get; set; } 36 | public Global Global { get; set; } 37 | } 38 | 39 | public class Namespace 40 | { 41 | public string Prefix { get; set; } 42 | public string Uri { get; set; } 43 | public string SchemaLocation { get; set; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Models/InvoiceItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facturapi 4 | { 5 | public class InvoiceItem 6 | { 7 | public Decimal Quantity { get; set; } 8 | public Decimal Discount { get; set; } 9 | public string Description { get; set; } 10 | public Product Product { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Models/Legal.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public class Legal { 4 | public string Name { get; set; } 5 | public string LegalName { get; set; } 6 | public string TaxId { get; set; } 7 | public string TaxSystem { get; set; } 8 | public string Website { get; set; } 9 | public string Phone { get; set; } 10 | public Address Address { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /Models/LiveApiKey.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public class LiveApiKey 4 | { 5 | public string First12 { get; set; } 6 | public string CreatedAt { get; set; } 7 | 8 | public string Id { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Models/Organization.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | public class Organization 7 | { 8 | public string Id { get; set; } 9 | public DateTime CreatedAt { get; set; } 10 | public bool IsProductionReady { get; set; } 11 | public List PendingSteps { get; set; } 12 | public Legal Legal { get; set; } 13 | public Customization Customization { get; set; } 14 | public Certificate Certificate { get; set; } 15 | 16 | public List ApiKeys { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Models/Payment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | public class Payment 7 | { 8 | public string PaymentForm { get; set; } 9 | public string Currency { get; set; } 10 | public Decimal Exchange { get; set; } 11 | public DateTime Date { get; set; } 12 | public List Related {get;set;} 13 | } 14 | 15 | public class PaymentRelated 16 | { 17 | public string Uuid { get; set; } 18 | public int Installment { get; set; } 19 | public Decimal LastBalance { get; set; } 20 | public Decimal Amount { get; set; } 21 | public string Currency { get; set; } 22 | public Decimal Exchange { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Models/PdfExtra.cs: -------------------------------------------------------------------------------- 1 | namespace Facturapi 2 | { 3 | public class PdfExtra 4 | { 5 | public bool Codes { get; set; } 6 | public bool ProductKey { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /Models/Product.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | public class Product 7 | { 8 | public string Id { get; set; } 9 | public bool Livemode { get; set; } 10 | public string ProductKey { get; set; } 11 | public string Description { get; set; } 12 | public Decimal Price { get; set; } 13 | public DateTime CreatedAt { get; set; } 14 | public bool TaxIncluded { get; set; } 15 | public List Taxes { get; set; } 16 | public string UnitKey { get; set; } 17 | public string UnitName { get; set; } 18 | public string Sku { get; set; } 19 | public string Taxability { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Models/Receipt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | public class Receipt 7 | { 8 | public string Id { get; set; } 9 | public string ExternalId { get; set; } 10 | public bool Livemode { get; set; } 11 | public DateTime CreatedAt { get; set; } 12 | public DateTime ExpiresAt { get; set; } 13 | public string SelfInvoiceUrl { get; set; } 14 | public string FolioNumber { get; set; } 15 | public string Key { get; set; } 16 | public string Branch { get; set; } 17 | public string Status { get; set; } 18 | public string Invoice { get; set; } 19 | public string PaymentForm { get; set; } 20 | public string Currency { get; set; } 21 | public Decimal Exchange { get; set; } 22 | public Decimal Total { get; set; } 23 | public List Items { get; set; } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Models/Retention.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | public class Retention 7 | { 8 | public string Id { get; set; } 9 | public string ExternalId { get; set; } 10 | public DateTime CreatedAt { get; set; } 11 | public Customer Customer { get; set; } 12 | public bool Livemode { get; set; } 13 | public string Status { get; set; } 14 | public string VerificationUrl { get; set; } 15 | public string Type { get; set; } 16 | public string Uuid { get; set; } 17 | public DateTime FechaExp { get; set; } 18 | public string CveRetenc { get; set; } 19 | public string FolioInt { get; set; } 20 | public string DescRetenc { get; set; } 21 | public RetentionPeriod Periodo { get; set; } 22 | public RetentionTotals Totales { get; set; } 23 | public List Namespaces { get; set; } 24 | public string[] Complements { get; set; } 25 | public string[] Addenda { get; set; } 26 | public string CancellationReceipt { get; set; } 27 | public Stamp Stamp { get; set; } 28 | public string PdfCustomSection { get; set; } 29 | } 30 | 31 | public class RetentionPeriod 32 | { 33 | public int MesIni { get; set; } 34 | public int MesFin { get; set; } 35 | public int Ejerc { get; set; } 36 | } 37 | 38 | public class RetentionTotals 39 | { 40 | public Decimal MontoTotGrav { get; set; } 41 | public Decimal MontoTotExent { get; set; } 42 | public Decimal MontoTotOperacion { get; set; } 43 | public Decimal MontoTotRet { get; set; } 44 | public RetentionRetainedTax[] ImpRetenidos { get; set; } 45 | } 46 | 47 | public class RetentionRetainedTax 48 | { 49 | public Decimal BaseRet { get; set; } 50 | public string Impuesto { get; set; } 51 | public Decimal MontoRet { get; set; } 52 | public bool PagoProvisional { get; set; } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Models/SearchResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Facturapi 4 | { 5 | public class SearchResult 6 | { 7 | public int Page { get; set; } 8 | public int TotalPages { get; set; } 9 | public int TotalResults { get; set; } 10 | public List Data { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Models/SeriesGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | public class SeriesGroup 7 | { 8 | public string Name { get; set; } 9 | public int NextFolio { get; set; } 10 | public int NextFolioTest { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Models/Stamp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | public class Stamp 7 | { 8 | public string Date { get; set; } 9 | public string SatSignature { get; set; } 10 | public string SatCertNumber { get; set; } 11 | public string Signature { get; set; } 12 | public string ComplementString { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Models/Tax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Newtonsoft.Json; 7 | 8 | namespace Facturapi 9 | { 10 | 11 | public class Tax 12 | { 13 | public string Type { get; set; } 14 | public decimal Rate { get; set; } 15 | public bool Withholding { get; set; } 16 | public string Factor {get; set;} 17 | public string IepsMode { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Models/TaxIdValidation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facturapi 8 | { 9 | public class EfosDetalle 10 | { 11 | public string Rfc { get; set; } 12 | public string RazonSocial { get; set; } 13 | public string SituacionContribuyente { get; set; } 14 | public string NumFechaPresuncion { get; set; } 15 | public string PubFechaSatPresuntos { get; set; } 16 | public string NumGlobalPresuncion { get; set; } 17 | public string PubFechaDofPresuntos { get; set; } 18 | public string PubSatDefinitivos { get; set; } 19 | public string PubDofDefinitivos { get; set; } 20 | public string NumFechaSentFav { get; set; } 21 | public string PubSatSentFav { get; set; } 22 | } 23 | 24 | public class EfosData 25 | { 26 | public string Mensaje { get; set; } 27 | public string FechaLista { get; set; } 28 | public List Detalles { get; set; } 29 | } 30 | 31 | public class Efos 32 | { 33 | public bool IsValid { get; set; } 34 | public EfosData Data { get; set; } 35 | } 36 | 37 | public class TaxIdValidation 38 | { 39 | public Efos Efos { get; set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Models/TaxInfoValidation.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Facturapi 4 | { 5 | public class TaxInfoError 6 | { 7 | public string Message { get; set; } 8 | public string Path { get; set; } 9 | } 10 | 11 | public class TaxInfoValidation 12 | { 13 | public bool IsValid { get; set; } 14 | public TaxInfoError[] Errors { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Models/Webhook.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facturapi 4 | { 5 | public class Webhook 6 | 7 | { 8 | public string Id { get; set; } 9 | public DateTime CreatedAt { get; set; } 10 | 11 | public string[] EnabledEvents { get; set; } 12 | 13 | public bool Livemode { get; set; } 14 | 15 | public Organization Organization { get; set; } 16 | 17 | public string Url { get; set; } 18 | 19 | public string Status { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /Models/WebhookValidateSignature.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facturapi 4 | { 5 | public class WebhookValidateSignature 6 | 7 | { 8 | public string Id { get; set; } 9 | public DateTime CreatedAt { get; set; } 10 | 11 | public bool Livemode { get; set; } 12 | 13 | public string Organization { get; set; } 14 | 15 | public string Type { get; set; } 16 | 17 | public object Data { get; set; } 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Facturapi .NET Library 2 | ====================== 3 | 4 | [![NuGet version](https://badge.fury.io/nu/Facturapi.svg)](https://www.nuget.org/packages/Facturapi/) 5 | [![NuGet downloads](https://img.shields.io/nuget/dt/Facturapi.svg)](https://www.nuget.org/packages/Facturapi/) 6 | 7 | Librería oficial para .NET de https://www.facturapi.io 8 | 9 | Facturapi ayuda a generar facturas electrónicas válidas en México (CFDI) de la manera más fácil posible. 10 | 11 | Si alguna vez has usado [Stripe](https://stripe.com) o [Conekta](https://conekta.io), verás que Facturapi es igual de sencillo de entender e integrar a tu aplicación. 12 | 13 | ## Instalación 14 | 15 | Puedes instalar Facturapi en tu proyecto usando [Nuget](https://www.nuget.org/) 16 | 17 | ```bash 18 | PM> Install-Package Facturapi 19 | ``` 20 | 21 | ## Antes de comenzar 22 | 23 | Asegúrate de haber creado tu cuenta gratuita en [Facturapi](https://www.facturapi.io) y de tener a la mano tus **API Keys**. 24 | 25 | ### Inicializa la librería usando tus llaves secretas 26 | 27 | Empieza por crear una instancia del Wrapper de Facturapi usando tu llave secreta. 28 | 29 | ```csharp 30 | using Facturapi; 31 | 32 | // Esto asegura que puedas usar diferentes ApiKeys en diferentes instancias de Wrapper 33 | var facturapi = new FacturapiClient('TU_API_KEY'); 34 | // Después, procede a llamar a los métodos como muestra la documentación. 35 | var invoice = await facturapi.Invoice.Create(...); 36 | ``` 37 | 38 | ### Métodos asíncronos (async, await) 39 | 40 | Esta librería utiliza métodos asíncronos. Si tu aplicación no tiene código asíncrono, puedes convertir un método asíncrono en síncrono de la siguiente manera: 41 | 42 | ```csharp 43 | // Asíncrono 44 | var customers = await facturapi.Customer.List(); 45 | 46 | // Síncrono 47 | var customers = facturapi.Customer.List().GetAwaiter().GetResult(); 48 | ``` 49 | 50 | ## Uso de la librería 51 | 52 | ### Crear un cliente 53 | 54 | ```csharp 55 | var customer = await facturapi.Customer.CreateAsync(new Dictionary 56 | { 57 | ["legal_name"] = "Walter White", // Razón social 58 | ["tax_id"] = "ABCD101010XYZ", // RFC 59 | ["email"] = "walter@example.com", // Email a donde se enviará la factura 60 | ["address"] = new Dictionary 61 | { 62 | ["street"] = "Sunset Blvd", // Calle 63 | ["exterior"] = "104", // Número exterior 64 | ["neighborhood"] = "Roma Norte", // Colonia 65 | ["zip"] = "44940" // Código postal 66 | // NOTA: La ciudad, municipio, estado y país se llenan automáticamente 67 | // a partir del código postal, pero si quieres puedes especificar sus valores. 68 | } 69 | }); 70 | 71 | // Recuerda guardar el customer.id en tu base de datos, lo 72 | // necesitarás a la hora de emitirle una factura. 73 | ``` 74 | 75 | ### Crear un producto 76 | 77 | ```csharp 78 | var product = await facturapi.Product.CreateAsync(new Dictionary 79 | { 80 | ["description"] = "iPhone 8", 81 | ["product_key"] = "4319150114", // Clave Producto/Servicio del catálogo del SAT. Para obtenerla más fácilmente 82 | // utiliza nuestra herramienta de búsqueda de claves en tu dashboard. 83 | ["price"] = 345.60 // Precio con IVA incluído, a menos que se especifique lo contrario. 84 | // Por default, se creará un impuesto automáticamente a partir del precio, aplicando el IVA al 16%. 85 | // Pero puedes sobreescribir los impuestos aplicables a este producto especificando un arreglo de impuestos: 86 | // taxes: new Dictionary[] { 87 | // new Dictionary 88 | // { 89 | // ["type"] = Facturapi.TaxType.IVA, 90 | // ["rate"] = 0.16 91 | // }, 92 | // new Dictionary 93 | // { 94 | // ["type"] = Facturapi.TaxType.ISR, 95 | // ["rate"] = 0.03666, 96 | // ["withholding"] = true 97 | // } 98 | // } 99 | }); 100 | 101 | // Recuerda guardar el product.id para generar facturas que incluyan este producto. 102 | ``` 103 | 104 | ### Crear una factura 105 | 106 | ```csharp 107 | var invoice = await facturapi.Product.CreateAsync(new Dictionary 108 | { 109 | ["customer"] = "ID_DEL_CLIENTE", // Para clientes no registrados, puedes asignar 110 | // un Dictionary con los datos del cliente. 111 | ["items"] = new Dictionary[] 112 | { // Puedes agregar tantos items como necesites a este arreglo 113 | new Dictionary 114 | { 115 | ["quantity"] = 2, // Opcional. Default: 1. 116 | ["product"] = "ID_DEL_PRODUCTO" // Para productos no registrados, puedes asignar 117 | // un Dictionary con los datos del producto. 118 | } 119 | } 120 | ["payment_form"] = Facturapi.PaymentForm.DINERO_ELECTRONICO 121 | }); 122 | ``` 123 | 124 | #### Descargar factura 125 | 126 | ```csharp 127 | // Una vez creada la factura, puedes descargar el PDF y el XML comprimidos 128 | // en un archivo ZIP. 129 | var zipStream = await facturapi.Invoice.DownloadZipAsync(invoice.Id); 130 | // O bien, el XML y el PDF por separado 131 | var xmlStream = await facturapi.Invoice.DownloadXmlAsync(invoice.Id); 132 | var pdfStream = await facturapi.Invoice.DownloadPdfAsync(invoice.Id); 133 | // Y luego guardarlo en un archivo del disco duro 134 | var file = new System.IO.FileStrem("C:\\route\\to\\save\\invoice.zip", FileMode.Create); 135 | zipStream.CopyTo(file); 136 | file.Close(); 137 | ``` 138 | 139 | #### Envía la factura por correo electrónico 140 | 141 | ```csharp 142 | await facturapi.Invoice.SendByEmailAsync(invoice.Id); 143 | ``` 144 | 145 | ## Documentación 146 | 147 | Hay muchas más cosas que puedes hacer con esta librería: listar, consultar, actualizar y eliminar clientes, productos y facturas. 148 | 149 | Ve la documentación completa en http://docs.facturapi.io. 150 | 151 | ## Ayuda 152 | 153 | ### ¿Encontraste un bug? 154 | 155 | Por favor repórtalo en el Issue Tracker de este repo. 156 | 157 | ### ¿Quieres contribuir? 158 | 159 | Mándanos un Pull Request! Agradecemos todo tipo de ayuda :) 160 | 161 | ### Contáctanos 162 | 163 | contacto@facturapi.io 164 | -------------------------------------------------------------------------------- /Router/CatalogRouter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Facturapi 4 | { 5 | internal static partial class Router 6 | { 7 | public static string SearchProductKeys(Dictionary query = null) 8 | { 9 | return UriWithQuery("catalogs/products", query); 10 | } 11 | 12 | public static string SearchUnitKeys(Dictionary query = null) 13 | { 14 | return UriWithQuery("catalogs/units", query); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Router/CustomerRouter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Facturapi 4 | { 5 | internal static partial class Router 6 | { 7 | public static string ListCustomers(Dictionary query = null) 8 | { 9 | return UriWithQuery("customers", query); 10 | } 11 | 12 | public static string RetrieveCustomer(string id, Dictionary query = null) 13 | { 14 | return $"{UriWithQuery($"customers/{id}", query)}"; 15 | } 16 | 17 | public static string ValidateCustomerTaxInfo(string id) 18 | { 19 | return $"customers/{id}/tax-info-validation"; 20 | } 21 | 22 | public static string CreateCustomer(Dictionary query = null) 23 | { 24 | return UriWithQuery("customers", query); 25 | } 26 | 27 | public static string DeleteCustomer(string id) 28 | { 29 | return RetrieveCustomer(id); 30 | } 31 | 32 | public static string UpdateCustomer(string id, Dictionary query = null) { 33 | return RetrieveCustomer(id, query); 34 | } 35 | 36 | public static string SendEditLinkByEmail(string id) 37 | { 38 | return $"{UriWithQuery($"customers/{id}/email-edit-link")}"; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Router/InvoiceRouter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facturapi 8 | { 9 | internal static partial class Router 10 | { 11 | public static string ListInvoices(Dictionary query = null) 12 | { 13 | return UriWithQuery("invoices", query); 14 | } 15 | 16 | public static string RetrieveInvoice(string id) 17 | { 18 | return $"invoices/{id}"; 19 | } 20 | 21 | public static string CreateInvoice(Dictionary query = null) 22 | { 23 | return UriWithQuery("invoices", query); 24 | } 25 | 26 | public static string CancelInvoice(string id, Dictionary query = null) 27 | { 28 | return UriWithQuery(RetrieveInvoice(id), query); 29 | } 30 | 31 | public static string DownloadInvoice(string id, string format) 32 | { 33 | return $"invoices/{id}/{format}"; 34 | } 35 | 36 | public static string DownloadCancellationReceipt(string id, string format) 37 | { 38 | return $"invoices/{id}/cancellation_receipt/{format}"; 39 | } 40 | 41 | public static string SendByEmail(string id) 42 | { 43 | return $"invoices/{id}/email"; 44 | } 45 | 46 | public static string UpdateStatus(string id) 47 | { 48 | return $"invoices/{id}/status"; 49 | } 50 | 51 | public static string UpdateDraftInvoice(string id) 52 | { 53 | return $"invoices/{id}"; 54 | } 55 | 56 | public static string StampDraftInvoice(string id, Dictionary query = null) 57 | { 58 | return UriWithQuery($"invoices/{id}/stamp", query); 59 | } 60 | 61 | public static string CopyInvoice(string id) 62 | { 63 | return $"invoices/{id}/copy"; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Router/OrganizationRouter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | internal static partial class Router 7 | { 8 | public static string ListOrganizations(Dictionary query = null) 9 | { 10 | return UriWithQuery("organizations", query); 11 | } 12 | 13 | public static string RetrieveOrganization(string id) 14 | { 15 | return $"organizations/{id}"; 16 | } 17 | 18 | public static string CreateOrganization() 19 | { 20 | return "organizations"; 21 | } 22 | 23 | public static string DeleteOrganization(string id) 24 | { 25 | return RetrieveOrganization(id); 26 | } 27 | 28 | public static string UpdateLegal(string id) 29 | { 30 | return $"{RetrieveOrganization(id)}/legal"; 31 | } 32 | 33 | public static string UpdateCustomization(string id) 34 | { 35 | return $"{RetrieveOrganization(id)}/customization"; 36 | } 37 | 38 | public static string UploadLogo(string id) 39 | { 40 | return $"{RetrieveOrganization(id)}/logo"; 41 | } 42 | 43 | public static string UploadCertificate(string id) 44 | { 45 | return $"{RetrieveOrganization(id)}/certificate"; 46 | } 47 | 48 | public static string DeleteCertificate(string id) 49 | { 50 | return $"{RetrieveOrganization(id)}/certificate"; 51 | } 52 | 53 | public static string GetTestApiKey(string id) 54 | { 55 | return $"{RetrieveOrganization(id)}/apikeys/test"; 56 | } 57 | 58 | 59 | public static string RenewTestApiKey(string id) 60 | { 61 | return $"{RetrieveOrganization(id)}/apikeys/test"; 62 | } 63 | 64 | public static string ListAsyncLiveApiKeys(string id) 65 | { 66 | return $"{RetrieveOrganization(id)}/apikeys/live"; 67 | } 68 | 69 | public static string RenewLiveApiKey(string id) 70 | { 71 | return $"{RetrieveOrganization(id)}/apikeys/live"; 72 | } 73 | 74 | public static string DeleteLiveApiKey(string organizationId, string apiKeyId) 75 | { 76 | return $"{RetrieveOrganization(organizationId)}/apikeys/live/{apiKeyId}"; 77 | } 78 | 79 | 80 | public static string ListSeriesGroup (string id) 81 | { 82 | return $"{RetrieveOrganization(id)}/series-group"; 83 | } 84 | 85 | public static string CreateSeriesGroup (string id) 86 | { 87 | return $"{RetrieveOrganization(id)}/series-group"; 88 | } 89 | 90 | public static string UpdateSeriesGroup (string id, string series_name) 91 | { 92 | return $"{RetrieveOrganization(id)}/series-group/{series_name}"; 93 | } 94 | public static string DeleteSeriesGroup (string id, string series_name) 95 | { 96 | return $"{RetrieveOrganization(id)}/series-group/{series_name}"; 97 | } 98 | 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Router/ProductRouter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facturapi 8 | { 9 | internal static partial class Router 10 | { 11 | public static string ListProducts(Dictionary query = null) 12 | { 13 | return UriWithQuery("products", query); 14 | } 15 | 16 | public static string RetrieveProduct(string id) 17 | { 18 | return $"products/{id}"; 19 | } 20 | 21 | public static string CreateProduct() 22 | { 23 | return "products"; 24 | } 25 | 26 | public static string DeleteProduct(string id) 27 | { 28 | return RetrieveProduct(id); 29 | } 30 | 31 | public static string UpdateProduct(string id) 32 | { 33 | return RetrieveProduct(id); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Router/ReceiptRouter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facturapi 8 | { 9 | internal static partial class Router 10 | { 11 | public static string ListReceipts(Dictionary query = null) 12 | { 13 | return UriWithQuery("receipts", query); 14 | } 15 | 16 | public static string RetrieveReceipt(string id) 17 | { 18 | return $"receipts/{id}"; 19 | } 20 | 21 | public static string CreateReceipt() 22 | { 23 | return "receipts"; 24 | } 25 | 26 | public static string CancelReceipt(string id) 27 | { 28 | return RetrieveReceipt(id); 29 | } 30 | 31 | public static string InvoiceReceipt(string id) 32 | { 33 | return $"receipts/(id)/invoice"; 34 | } 35 | 36 | public static string CreateGlobalInvoice(string id) 37 | { 38 | return $"receipts/global-invoice"; 39 | } 40 | 41 | public static string DownloadReceiptPdf(string id) 42 | { 43 | return $"receipts/(id)/pdf"; 44 | } 45 | 46 | public static string SendReceiptByEmail(string id) 47 | { 48 | return $"receipts/(id)/email"; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Router/RetentionRouter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facturapi 8 | { 9 | internal static partial class Router 10 | { 11 | public static string ListRetentionss(Dictionary query = null) 12 | { 13 | return UriWithQuery("retentions", query); 14 | } 15 | 16 | public static string RetrieveRetention(string id) 17 | { 18 | return $"retentions/{id}"; 19 | } 20 | 21 | public static string CreateRetention() 22 | { 23 | return "retentions"; 24 | } 25 | 26 | public static string CancelRetention(string id) 27 | { 28 | return RetrieveRetention(id); 29 | } 30 | 31 | public static string DownloadRetention(string id, string format) 32 | { 33 | return $"retentions/{id}/{format}"; 34 | } 35 | 36 | public static string SendRetentionByEmail(string id) 37 | { 38 | return $"retentions/{id}/email"; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Router/Router.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Facturapi 6 | { 7 | internal static partial class Router 8 | { 9 | private static string UriWithQuery(string path, Dictionary query = null) 10 | { 11 | var url = path; 12 | if (query != null) 13 | { 14 | return $"{path}?{DictionaryToQueryString(query)}"; 15 | } 16 | else 17 | { 18 | return path; 19 | } 20 | } 21 | 22 | private static string DictionaryToQueryString(Dictionary dict) 23 | { 24 | return String.Join("&", dict.Select(x => String.Format("{0}={1}", Uri.EscapeDataString(x.Key), Uri.EscapeDataString(x.Value.ToString())))); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Router/ToolRouter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Facturapi 4 | { 5 | internal static partial class Router 6 | { 7 | public static string ValidateTaxId(Dictionary query = null) 8 | { 9 | return UriWithQuery("tools/tax_id_validation", query); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Router/WebhookRouter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Facturapi 5 | { 6 | internal static partial class Router 7 | { 8 | public static string ListWebhooks(Dictionary query = null) 9 | { 10 | return UriWithQuery("webhooks", query); 11 | } 12 | 13 | public static string RetrieveWebhook(string id) 14 | { 15 | return $"webhooks/{id}"; 16 | } 17 | 18 | public static string CreateWebhook() 19 | { 20 | return "webhooks"; 21 | } 22 | 23 | public static string UpdateWebhook(string id) 24 | { 25 | return RetrieveWebhook(id); 26 | } 27 | 28 | public static string DeleteWebhook(string id) 29 | { 30 | return RetrieveWebhook(id); 31 | } 32 | 33 | public static string ValidateSignature() 34 | { 35 | return "webhooks/validate-signature"; 36 | } 37 | 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Util/SnakeCasePropertyNamesContractResolver.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Serialization; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Facturapi 9 | { 10 | internal class SnakeCasePropertyNamesContractResolver : DefaultContractResolver 11 | { 12 | protected override string ResolvePropertyName(string propertyName) 13 | { 14 | var startUnderscores = System.Text.RegularExpressions.Regex.Match(propertyName, @"^_+"); 15 | return startUnderscores + System.Text.RegularExpressions.Regex 16 | .Replace(propertyName, @"([A-Z])", "_$1").ToLower().TrimStart('_'); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Wrappers/BaseWrapper.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Net.Http; 4 | using System.Text; 5 | 6 | namespace Facturapi.Wrappers 7 | { 8 | public abstract class BaseWrapper 9 | { 10 | protected const string BASE_URL = "https://www.facturapi.io/"; 11 | protected HttpClient client; 12 | protected JsonSerializerSettings jsonSettings { get; set; } 13 | public string apiKey { get; set; } 14 | public string apiVersion { get; set; } 15 | 16 | public BaseWrapper(string apiKey, string apiVersion = "v2") 17 | { 18 | var apiKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(apiKey + ":")); 19 | this.client = new HttpClient() 20 | { 21 | BaseAddress = new Uri($"{BASE_URL}/{apiVersion}/") 22 | }; 23 | this.client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", apiKeyBase64); 24 | this.jsonSettings = new JsonSerializerSettings 25 | { 26 | ContractResolver = new SnakeCasePropertyNamesContractResolver(), 27 | NullValueHandling = NullValueHandling.Ignore 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Wrappers/CatalogWrapper.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System.Collections.Generic; 4 | using System.Net.Http; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Facturapi.Wrappers 9 | { 10 | public class CatalogWrapper : BaseWrapper 11 | { 12 | public CatalogWrapper(string apiKey, string apiVersion = "v2") : base(apiKey, apiVersion) 13 | { 14 | } 15 | 16 | public async Task> SearchProducts(Dictionary query = null) 17 | { 18 | var response = await client.GetAsync(Router.SearchProductKeys(query)); 19 | var resultString = await response.Content.ReadAsStringAsync(); 20 | 21 | if (!response.IsSuccessStatusCode) 22 | { 23 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 24 | throw new FacturapiException(error["message"].ToString()); 25 | } 26 | 27 | var searchResult = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 28 | return searchResult; 29 | } 30 | 31 | public async Task> SearchUnits(Dictionary query = null) 32 | { 33 | var response = await client.GetAsync(Router.SearchUnitKeys(query)); 34 | var resultString = await response.Content.ReadAsStringAsync(); 35 | 36 | if (!response.IsSuccessStatusCode) 37 | { 38 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 39 | throw new FacturapiException(error["message"].ToString()); 40 | } 41 | 42 | var searchResult = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 43 | return searchResult; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Wrappers/CustomerWrapper.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Net.Http; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Facturapi.Wrappers 11 | { 12 | public class CustomerWrapper : BaseWrapper 13 | { 14 | public CustomerWrapper(string apiKey, string apiVersion = "v2") : base(apiKey, apiVersion) 15 | { 16 | } 17 | 18 | public async Task> ListAsync(Dictionary query = null) 19 | { 20 | var response = await client.GetAsync(Router.ListCustomers(query)); 21 | var resultString = await response.Content.ReadAsStringAsync(); 22 | 23 | if (!response.IsSuccessStatusCode) 24 | { 25 | var error = JsonConvert.DeserializeObject(resultString); 26 | throw new FacturapiException(error["message"].ToString()); 27 | } 28 | 29 | var searchResult = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 30 | return searchResult; 31 | } 32 | 33 | public async Task CreateAsync(Dictionary data, Dictionary queryParams = null) 34 | { 35 | var response = await client.PostAsync(Router.CreateCustomer(queryParams), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 36 | var resultString = await response.Content.ReadAsStringAsync(); 37 | if (!response.IsSuccessStatusCode) 38 | { 39 | var error = JsonConvert.DeserializeObject(resultString); 40 | throw new FacturapiException(error["message"].ToString()); 41 | } 42 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 43 | return customer; 44 | } 45 | 46 | public async Task RetrieveAsync(string id) 47 | { 48 | var response = await client.GetAsync(Router.RetrieveCustomer(id)); 49 | var resultString = await response.Content.ReadAsStringAsync(); 50 | if (!response.IsSuccessStatusCode) 51 | { 52 | var error = JsonConvert.DeserializeObject(resultString); 53 | throw new FacturapiException(error["message"].ToString()); 54 | } 55 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 56 | return customer; 57 | } 58 | 59 | public async Task DeleteAsync(string id) 60 | { 61 | var response = await client.DeleteAsync(Router.DeleteCustomer(id)); 62 | var resultString = await response.Content.ReadAsStringAsync(); 63 | if (!response.IsSuccessStatusCode) 64 | { 65 | var error = JsonConvert.DeserializeObject(resultString); 66 | throw new FacturapiException(error["message"].ToString()); 67 | } 68 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 69 | return customer; 70 | } 71 | 72 | public async Task UpdateAsync(string id, Dictionary data, Dictionary queryParams = null) 73 | { 74 | var response = await client.PutAsync(Router.UpdateCustomer(id, queryParams), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 75 | var resultString = await response.Content.ReadAsStringAsync(); 76 | if (!response.IsSuccessStatusCode) 77 | { 78 | var error = JsonConvert.DeserializeObject(resultString); 79 | throw new FacturapiException(error["message"].ToString()); 80 | } 81 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 82 | return customer; 83 | } 84 | 85 | public async Task ValidateTaxInfoAsync(string id) 86 | { 87 | var response = await client.GetAsync(Router.ValidateCustomerTaxInfo(id)); 88 | var resultString = await response.Content.ReadAsStringAsync(); 89 | if (!response.IsSuccessStatusCode) 90 | { 91 | var error = JsonConvert.DeserializeObject(resultString); 92 | throw new FacturapiException(error["message"].ToString()); 93 | } 94 | var validation = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 95 | return validation; 96 | } 97 | 98 | public async Task SendEditLinkByEmailAsync(string id, Dictionary data) 99 | { 100 | var response = await client.PostAsync(Router.SendEditLinkByEmail(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 101 | if (!response.IsSuccessStatusCode) 102 | { 103 | var resultString = await response.Content.ReadAsStringAsync(); 104 | var error = JsonConvert.DeserializeObject(resultString); 105 | var errorMessage = error["message"] != null ? error["message"].ToString() : "An error occurred"; 106 | throw new FacturapiException(errorMessage); 107 | } 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Wrappers/InvoiceWrapper.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Net.Http; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace Facturapi.Wrappers 12 | { 13 | public class InvoiceWrapper : BaseWrapper 14 | { 15 | public InvoiceWrapper(string apiKey, string apiVersion = "v2") : base(apiKey, apiVersion) 16 | { 17 | } 18 | 19 | public async Task> ListAsync(Dictionary query = null) 20 | { 21 | var response = await client.GetAsync(Router.ListInvoices(query)); 22 | var resultString = await response.Content.ReadAsStringAsync(); 23 | 24 | if (!response.IsSuccessStatusCode) 25 | { 26 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 27 | throw new FacturapiException(error["message"].ToString()); 28 | } 29 | 30 | var searchResult = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 31 | return searchResult; 32 | } 33 | 34 | public async Task CreateAsync(Dictionary data, Dictionary options = null) 35 | { 36 | var response = await client.PostAsync(Router.CreateInvoice(options), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 37 | var resultString = await response.Content.ReadAsStringAsync(); 38 | if (!response.IsSuccessStatusCode) 39 | { 40 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 41 | throw new FacturapiException(error["message"].ToString()); 42 | } 43 | var invoice = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 44 | return invoice; 45 | } 46 | 47 | public async Task RetrieveAsync(string id) 48 | { 49 | var response = await client.GetAsync(Router.RetrieveInvoice(id)); 50 | var resultString = await response.Content.ReadAsStringAsync(); 51 | if (!response.IsSuccessStatusCode) 52 | { 53 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 54 | throw new FacturapiException(error["message"].ToString()); 55 | } 56 | var invoice = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 57 | return invoice; 58 | } 59 | 60 | public async Task CancelAsync(string id, Dictionary query = null) 61 | { 62 | var response = await client.DeleteAsync(Router.CancelInvoice(id, query)); 63 | var resultString = await response.Content.ReadAsStringAsync(); 64 | if (!response.IsSuccessStatusCode) 65 | { 66 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 67 | throw new FacturapiException(error["message"].ToString()); 68 | } 69 | var invoice = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 70 | return invoice; 71 | } 72 | 73 | public async Task SendByEmailAsync(string id, Dictionary data) 74 | { 75 | var response = await client.PostAsync(Router.SendByEmail(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 76 | if (!response.IsSuccessStatusCode) 77 | { 78 | var resultString = await response.Content.ReadAsStringAsync(); 79 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 80 | throw new FacturapiException(error["message"].ToString()); 81 | } 82 | } 83 | 84 | private async Task DownloadAsync(string id, string format) 85 | { 86 | var response = await client.GetAsync(Router.DownloadInvoice(id, format)); 87 | if (!response.IsSuccessStatusCode) 88 | { 89 | var resultString = await response.Content.ReadAsStringAsync(); 90 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 91 | throw new FacturapiException(error["message"].ToString()); 92 | } 93 | var stream = await response.Content.ReadAsStreamAsync(); 94 | return stream; 95 | } 96 | 97 | public Task DownloadZipAsync(string id) 98 | { 99 | return this.DownloadAsync(id, "zip"); 100 | } 101 | 102 | public Task DownloadPdfAsync(string id) 103 | { 104 | return this.DownloadAsync(id, "pdf"); 105 | } 106 | 107 | public Task DownloadXmlAsync(string id) 108 | { 109 | return this.DownloadAsync(id, "xml"); 110 | } 111 | 112 | private async Task DownloadCancellationReceiptAsync(string id, string format) 113 | { 114 | var response = await client.GetAsync(Router.DownloadCancellationReceipt(id, format)); 115 | if (!response.IsSuccessStatusCode) 116 | { 117 | var resultString = await response.Content.ReadAsStringAsync(); 118 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 119 | throw new FacturapiException(error["message"].ToString()); 120 | } 121 | var stream = await response.Content.ReadAsStreamAsync(); 122 | return stream; 123 | } 124 | 125 | public Task DownloadCancellationReceiptXmlAsync(string id) 126 | { 127 | return DownloadCancellationReceiptAsync(id, "xml"); 128 | } 129 | 130 | public Task DownloadCancellationReceiptPdfAsync(string id) 131 | { 132 | return DownloadCancellationReceiptAsync(id, "pdf"); 133 | } 134 | 135 | public async Task UpdateStatus(string id) 136 | { 137 | var response = await client.PutAsync(Router.UpdateStatus(id), new StringContent("", Encoding.UTF8, "application/json")); 138 | var resultString = await response.Content.ReadAsStringAsync(); 139 | if (!response.IsSuccessStatusCode) 140 | { 141 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 142 | throw new FacturapiException(error["message"].ToString()); 143 | } 144 | var invoice = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 145 | return invoice; 146 | } 147 | 148 | public async Task UpdateDraftAsync(string id, Dictionary data) 149 | { 150 | var response = await client.PutAsync(Router.UpdateDraftInvoice(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 151 | var resultString = await response.Content.ReadAsStringAsync(); 152 | if (!response.IsSuccessStatusCode) 153 | { 154 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 155 | throw new FacturapiException(error["message"].ToString()); 156 | } 157 | var invoice = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 158 | return invoice; 159 | } 160 | 161 | public async Task StampDraft(string id, Dictionary options = null) 162 | { 163 | var response = await client.PostAsync(Router.StampDraftInvoice(id, options), new StringContent("", Encoding.UTF8, "application/json")); 164 | var resultString = await response.Content.ReadAsStringAsync(); 165 | if (!response.IsSuccessStatusCode) 166 | { 167 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 168 | throw new FacturapiException(error["message"].ToString()); 169 | } 170 | var invoice = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 171 | return invoice; 172 | } 173 | 174 | public async Task CopyToDraftAsync(string id) 175 | { 176 | var response = await client.PostAsync(Router.CopyInvoice(id), new StringContent("", Encoding.UTF8, "application/json")); 177 | var resultString = await response.Content.ReadAsStringAsync(); 178 | if (!response.IsSuccessStatusCode) 179 | { 180 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 181 | throw new FacturapiException(error["message"].ToString()); 182 | } 183 | var invoice = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 184 | return invoice; 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /Wrappers/OrganizationWrapper.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Net.Http; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Facturapi.Wrappers 10 | { 11 | public class OrganizationWrapper : BaseWrapper 12 | { 13 | public OrganizationWrapper(string apiKey, string apiVersion = "v2") : base(apiKey, apiVersion) 14 | { 15 | } 16 | 17 | public async Task> ListAsync(Dictionary query = null) 18 | { 19 | var response = await client.GetAsync(Router.ListOrganizations(query)); 20 | var resultString = await response.Content.ReadAsStringAsync(); 21 | 22 | if (!response.IsSuccessStatusCode) 23 | { 24 | var error = JsonConvert.DeserializeObject(resultString); 25 | throw new FacturapiException(error["message"].ToString()); 26 | } 27 | 28 | var searchResult = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 29 | return searchResult; 30 | } 31 | 32 | public async Task CreateAsync(Dictionary data) 33 | { 34 | var response = await client.PostAsync(Router.CreateOrganization(), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 35 | var resultString = await response.Content.ReadAsStringAsync(); 36 | if (!response.IsSuccessStatusCode) 37 | { 38 | var error = JsonConvert.DeserializeObject(resultString); 39 | throw new FacturapiException(error["message"].ToString()); 40 | } 41 | var organization = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 42 | return organization; 43 | } 44 | 45 | public async Task RetrieveAsync(string id) 46 | { 47 | var response = await client.GetAsync(Router.RetrieveOrganization(id)); 48 | var resultString = await response.Content.ReadAsStringAsync(); 49 | if (!response.IsSuccessStatusCode) 50 | { 51 | var error = JsonConvert.DeserializeObject(resultString); 52 | throw new FacturapiException(error["message"].ToString()); 53 | } 54 | var organization = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 55 | return organization; 56 | } 57 | 58 | public async Task DeleteAsync(string id) 59 | { 60 | var response = await client.DeleteAsync(Router.DeleteOrganization(id)); 61 | var resultString = await response.Content.ReadAsStringAsync(); 62 | if (!response.IsSuccessStatusCode) 63 | { 64 | var error = JsonConvert.DeserializeObject(resultString); 65 | throw new FacturapiException(error["message"].ToString()); 66 | } 67 | var organization = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 68 | return organization; 69 | } 70 | 71 | public async Task UploadLogoAsync(string id, Stream file) 72 | { 73 | var form = new MultipartFormDataContent(); 74 | form.Add(new StreamContent(file), "file", "logo.jpg"); 75 | var response = await client.PutAsync(Router.UploadLogo(id), form); 76 | var resultString = await response.Content.ReadAsStringAsync(); 77 | if (!response.IsSuccessStatusCode) 78 | { 79 | var error = JsonConvert.DeserializeObject(resultString); 80 | throw new FacturapiException(error["message"].ToString()); 81 | } 82 | var organization = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 83 | return organization; 84 | } 85 | 86 | public async Task UploadCertificateAsync(string id, Stream cerFile, Stream keyFile, string password) 87 | { 88 | var form = new MultipartFormDataContent(); 89 | form.Add(new StreamContent(cerFile), "cer", "certificate.cer"); 90 | form.Add(new StreamContent(keyFile), "key", "key.key"); 91 | form.Add(new StringContent(password), "password"); 92 | var response = await client.PutAsync(Router.UploadCertificate(id), form); 93 | var resultString = await response.Content.ReadAsStringAsync(); 94 | if (!response.IsSuccessStatusCode) 95 | { 96 | var error = JsonConvert.DeserializeObject(resultString); 97 | throw new FacturapiException(error["message"].ToString()); 98 | } 99 | var organization = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 100 | return organization; 101 | } 102 | 103 | public async Task DeleteCertificateAsync(string id) 104 | { 105 | var response = await client.DeleteAsync(Router.DeleteCertificate(id)); 106 | var resultString = await response.Content.ReadAsStringAsync(); 107 | if (!response.IsSuccessStatusCode) 108 | { 109 | var error = JsonConvert.DeserializeObject(resultString); 110 | throw new FacturapiException(error["message"].ToString()); 111 | } 112 | var certificateInfo = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 113 | return certificateInfo; 114 | } 115 | 116 | public async Task UpdateLegalAsync(string id, Dictionary data) 117 | { 118 | var response = await client.PutAsync(Router.UpdateLegal(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 119 | var resultString = await response.Content.ReadAsStringAsync(); 120 | if (!response.IsSuccessStatusCode) 121 | { 122 | var error = JsonConvert.DeserializeObject(resultString); 123 | throw new FacturapiException(error["message"].ToString()); 124 | } 125 | var organization = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 126 | return organization; 127 | } 128 | 129 | public async Task UpdateCustomizationAsync(string id, Dictionary data) 130 | { 131 | var response = await client.PutAsync(Router.UpdateCustomization(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 132 | var resultString = await response.Content.ReadAsStringAsync(); 133 | if (!response.IsSuccessStatusCode) 134 | { 135 | var error = JsonConvert.DeserializeObject(resultString); 136 | throw new FacturapiException(error["message"].ToString()); 137 | } 138 | var organization = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 139 | return organization; 140 | } 141 | 142 | public async Task GetTestApiKeyAsync(string id) 143 | { 144 | var response = await client.GetAsync(Router.GetTestApiKey(id)); 145 | var resultString = await response.Content.ReadAsStringAsync(); 146 | if (!response.IsSuccessStatusCode) 147 | { 148 | var error = JsonConvert.DeserializeObject(resultString); 149 | throw new FacturapiException(error["message"].ToString()); 150 | } 151 | return resultString; 152 | } 153 | 154 | 155 | public async Task RenewTestApiKeyAsync(string id) 156 | { 157 | var response = await client.PutAsync(Router.RenewTestApiKey(id), new StringContent("")); 158 | var resultString = await response.Content.ReadAsStringAsync(); 159 | if (!response.IsSuccessStatusCode) 160 | { 161 | var error = JsonConvert.DeserializeObject(resultString); 162 | throw new FacturapiException(error["message"].ToString()); 163 | } 164 | return resultString; 165 | } 166 | 167 | public async Task ListLiveApiKeysAsync(string id) 168 | { 169 | var response = await client.GetAsync(Router.ListAsyncLiveApiKeys(id)); 170 | var resultString = await response.Content.ReadAsStringAsync(); 171 | if (!response.IsSuccessStatusCode) 172 | { 173 | var error = JsonConvert.DeserializeObject(resultString); 174 | throw new FacturapiException(error["message"].ToString()); 175 | } 176 | var listResult = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 177 | 178 | return listResult; 179 | } 180 | 181 | public async Task RenewLiveApiKeyAsync(string id) 182 | { 183 | var response = await client.PutAsync(Router.RenewLiveApiKey(id), new StringContent("")); 184 | var resultString = await response.Content.ReadAsStringAsync(); 185 | if (!response.IsSuccessStatusCode) 186 | { 187 | var error = JsonConvert.DeserializeObject(resultString); 188 | throw new FacturapiException(error["message"].ToString()); 189 | } 190 | return resultString; 191 | } 192 | 193 | 194 | public async Task> ListSeriesGroupAsync(string id) 195 | { 196 | var response = await client.GetAsync(Router.ListSeriesGroup(id)); 197 | var resultString = await response.Content.ReadAsStringAsync(); 198 | 199 | if (!response.IsSuccessStatusCode) 200 | { 201 | var error = JsonConvert.DeserializeObject(resultString); 202 | throw new FacturapiException(error["message"].ToString()); 203 | } 204 | 205 | var searchResult = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 206 | return searchResult; 207 | } 208 | 209 | public async Task CreateSeriesGroupAsync(string id, Dictionary data) 210 | { 211 | var response = await client.PutAsync(Router.CreateSeriesGroup(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 212 | var resultString = await response.Content.ReadAsStringAsync(); 213 | if (!response.IsSuccessStatusCode) 214 | { 215 | var error = JsonConvert.DeserializeObject(resultString); 216 | throw new FacturapiException(error["message"].ToString()); 217 | } 218 | var series = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 219 | return series; 220 | } 221 | 222 | public async Task UpdateSeriesGroupAsync(string id, string seriesName, Dictionary data) 223 | { 224 | var response = await client.PutAsync(Router.UpdateSeriesGroup(id, seriesName), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 225 | var resultString = await response.Content.ReadAsStringAsync(); 226 | if (!response.IsSuccessStatusCode) 227 | { 228 | var error = JsonConvert.DeserializeObject(resultString); 229 | throw new FacturapiException(error["message"].ToString()); 230 | } 231 | var series = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 232 | return series; 233 | } 234 | 235 | public async Task DeleteSeriesGroupAsync(string id, string seriesName) 236 | { 237 | var response = await client.DeleteAsync(Router.UpdateSeriesGroup(id, seriesName)); 238 | 239 | var resultString = await response.Content.ReadAsStringAsync(); 240 | if (!response.IsSuccessStatusCode) 241 | { 242 | var error = JsonConvert.DeserializeObject(resultString); 243 | throw new FacturapiException(error["message"].ToString()); 244 | } 245 | var series = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 246 | return series; 247 | } 248 | 249 | public async Task> DeleteLiveApiKeyAsync(string id, string apiKeyId) 250 | { 251 | var response = await client.DeleteAsync(Router.DeleteLiveApiKey(id, apiKeyId)); 252 | var resultString = await response.Content.ReadAsStringAsync(); 253 | if (!response.IsSuccessStatusCode) 254 | { 255 | var error = JsonConvert.DeserializeObject(resultString); 256 | throw new FacturapiException(error["message"].ToString()); 257 | } 258 | var deserializeJson = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 259 | return deserializeJson; 260 | } 261 | } 262 | } 263 | -------------------------------------------------------------------------------- /Wrappers/ProductWrapper.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Net.Http; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Facturapi.Wrappers 11 | { 12 | public class ProductWrapper : BaseWrapper 13 | { 14 | public ProductWrapper(string apiKey, string apiVersion = "v2") : base(apiKey, apiVersion) 15 | { 16 | } 17 | 18 | public async Task> ListAsync(Dictionary query = null) 19 | { 20 | var response = await client.GetAsync(Router.ListProducts(query)); 21 | var resultString = await response.Content.ReadAsStringAsync(); 22 | 23 | if (!response.IsSuccessStatusCode) 24 | { 25 | var error = JsonConvert.DeserializeObject(resultString); 26 | throw new FacturapiException(error["message"].ToString()); 27 | } 28 | 29 | var searchResult = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 30 | return searchResult; 31 | } 32 | 33 | public async Task CreateAsync(Dictionary data) 34 | { 35 | var response = await client.PostAsync(Router.CreateProduct(), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 36 | var resultString = await response.Content.ReadAsStringAsync(); 37 | if (!response.IsSuccessStatusCode) 38 | { 39 | var error = JsonConvert.DeserializeObject(resultString); 40 | throw new FacturapiException(error["message"].ToString()); 41 | } 42 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 43 | return customer; 44 | } 45 | 46 | public async Task RetrieveAsync(string id) 47 | { 48 | var response = await client.GetAsync(Router.RetrieveProduct(id)); 49 | var resultString = await response.Content.ReadAsStringAsync(); 50 | if (!response.IsSuccessStatusCode) 51 | { 52 | var error = JsonConvert.DeserializeObject(resultString); 53 | throw new FacturapiException(error["message"].ToString()); 54 | } 55 | var product = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 56 | return product; 57 | } 58 | 59 | public async Task DeleteAsync(string id) 60 | { 61 | var response = await client.DeleteAsync(Router.DeleteProduct(id)); 62 | var resultString = await response.Content.ReadAsStringAsync(); 63 | if (!response.IsSuccessStatusCode) 64 | { 65 | var error = JsonConvert.DeserializeObject(resultString); 66 | throw new FacturapiException(error["message"].ToString()); 67 | } 68 | var product = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 69 | return product; 70 | } 71 | 72 | public async Task UpdateAsync(string id, Dictionary data) 73 | { 74 | var response = await client.PutAsync(Router.UpdateProduct(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 75 | var resultString = await response.Content.ReadAsStringAsync(); 76 | if (!response.IsSuccessStatusCode) 77 | { 78 | var error = JsonConvert.DeserializeObject(resultString); 79 | throw new FacturapiException(error["message"].ToString()); 80 | } 81 | var product = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 82 | return product; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Wrappers/ReceiptWrapper.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Net.Http; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Facturapi.Wrappers 10 | { 11 | public class ReceiptWrapper : BaseWrapper 12 | { 13 | public ReceiptWrapper(string apiKey, string apiVersion = "v2") : base(apiKey, apiVersion) 14 | { 15 | } 16 | 17 | public async Task> ListAsync(Dictionary query = null) 18 | { 19 | var response = await client.GetAsync(Router.ListReceipts(query)); 20 | var resultString = await response.Content.ReadAsStringAsync(); 21 | 22 | if (!response.IsSuccessStatusCode) 23 | { 24 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 25 | throw new FacturapiException(error["message"].ToString()); 26 | } 27 | 28 | var searchResult = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 29 | return searchResult; 30 | } 31 | 32 | public async Task CreateAsync(Dictionary data) 33 | { 34 | var response = await client.PostAsync(Router.CreateReceipt(), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 35 | var resultString = await response.Content.ReadAsStringAsync(); 36 | if (!response.IsSuccessStatusCode) 37 | { 38 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 39 | throw new FacturapiException(error["message"].ToString()); 40 | } 41 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 42 | return customer; 43 | } 44 | 45 | public async Task RetrieveAsync(string id) 46 | { 47 | var response = await client.GetAsync(Router.RetrieveReceipt(id)); 48 | var resultString = await response.Content.ReadAsStringAsync(); 49 | if (!response.IsSuccessStatusCode) 50 | { 51 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 52 | throw new FacturapiException(error["message"].ToString()); 53 | } 54 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 55 | return customer; 56 | } 57 | 58 | public async Task CancelAsync(string id) 59 | { 60 | var response = await client.DeleteAsync(Router.CancelInvoice(id)); 61 | var resultString = await response.Content.ReadAsStringAsync(); 62 | if (!response.IsSuccessStatusCode) 63 | { 64 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 65 | throw new FacturapiException(error["message"].ToString()); 66 | } 67 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 68 | return customer; 69 | } 70 | 71 | public async Task InvoiceAsync(string id, Dictionary data) 72 | { 73 | var response = await client.PostAsync(Router.InvoiceReceipt(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 74 | if (!response.IsSuccessStatusCode) 75 | { 76 | var resultString = await response.Content.ReadAsStringAsync(); 77 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 78 | throw new FacturapiException(error["message"].ToString()); 79 | } 80 | } 81 | 82 | public async Task CreateGlobalInvoiceAsync(string id, Dictionary data) 83 | { 84 | var response = await client.PostAsync(Router.CreateGlobalInvoice(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 85 | if (!response.IsSuccessStatusCode) 86 | { 87 | var resultString = await response.Content.ReadAsStringAsync(); 88 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 89 | throw new FacturapiException(error["message"].ToString()); 90 | } 91 | } 92 | 93 | public async Task SendByEmailAsync(string id, Dictionary data) 94 | { 95 | var response = await client.PostAsync(Router.SendReceiptByEmail(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 96 | if (!response.IsSuccessStatusCode) 97 | { 98 | var resultString = await response.Content.ReadAsStringAsync(); 99 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 100 | throw new FacturapiException(error["message"].ToString()); 101 | } 102 | } 103 | 104 | public async Task DownloadPdfAsync(string id) 105 | { 106 | var response = await client.GetAsync(Router.DownloadReceiptPdf(id)); 107 | if (!response.IsSuccessStatusCode) 108 | { 109 | var resultString = await response.Content.ReadAsStringAsync(); 110 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 111 | throw new FacturapiException(error["message"].ToString()); 112 | } 113 | var stream = await response.Content.ReadAsStreamAsync(); 114 | return stream; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Wrappers/RetentionWrapper.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Net.Http; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace Facturapi.Wrappers 12 | { 13 | public class RetentionWrapper : BaseWrapper 14 | { 15 | public RetentionWrapper(string apiKey, string apiVersion = "v2") : base(apiKey, apiVersion) 16 | { 17 | } 18 | 19 | public async Task> ListAsync(Dictionary query = null) 20 | { 21 | var response = await client.GetAsync(Router.ListRetentionss(query)); 22 | var resultString = await response.Content.ReadAsStringAsync(); 23 | 24 | if (!response.IsSuccessStatusCode) 25 | { 26 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 27 | throw new FacturapiException(error["message"].ToString()); 28 | } 29 | 30 | var searchResult = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 31 | return searchResult; 32 | } 33 | 34 | public async Task CreateAsync(Dictionary data) 35 | { 36 | var response = await client.PostAsync(Router.CreateRetention(), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 37 | var resultString = await response.Content.ReadAsStringAsync(); 38 | if (!response.IsSuccessStatusCode) 39 | { 40 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 41 | throw new FacturapiException(error["message"].ToString()); 42 | } 43 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 44 | return customer; 45 | } 46 | 47 | public async Task RetrieveAsync(string id) 48 | { 49 | var response = await client.GetAsync(Router.RetrieveRetention(id)); 50 | var resultString = await response.Content.ReadAsStringAsync(); 51 | if (!response.IsSuccessStatusCode) 52 | { 53 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 54 | throw new FacturapiException(error["message"].ToString()); 55 | } 56 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 57 | return customer; 58 | } 59 | 60 | public async Task CancelAsync(string id) 61 | { 62 | var response = await client.DeleteAsync(Router.CancelRetention(id)); 63 | var resultString = await response.Content.ReadAsStringAsync(); 64 | if (!response.IsSuccessStatusCode) 65 | { 66 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 67 | throw new FacturapiException(error["message"].ToString()); 68 | } 69 | var customer = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 70 | return customer; 71 | } 72 | 73 | public async Task SendByEmailAsync(string id, Dictionary data) 74 | { 75 | var response = await client.PostAsync(Router.SendRetentionByEmail(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 76 | if (!response.IsSuccessStatusCode) 77 | { 78 | var resultString = await response.Content.ReadAsStringAsync(); 79 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 80 | throw new FacturapiException(error["message"].ToString()); 81 | } 82 | } 83 | 84 | private async Task DownloadAsync(string id, string format) 85 | { 86 | var response = await client.GetAsync(Router.DownloadRetention(id, format)); 87 | if (!response.IsSuccessStatusCode) 88 | { 89 | var resultString = await response.Content.ReadAsStringAsync(); 90 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 91 | throw new FacturapiException(error["message"].ToString()); 92 | } 93 | var stream = await response.Content.ReadAsStreamAsync(); 94 | return stream; 95 | } 96 | 97 | public Task DownloadZipAsync(string id) 98 | { 99 | return this.DownloadAsync(id, "zip"); 100 | } 101 | 102 | public Task DownloadPdfAsync(string id) 103 | { 104 | return this.DownloadAsync(id, "pdf"); 105 | } 106 | 107 | public Task DownloadXmlAsync(string id) 108 | { 109 | return this.DownloadAsync(id, "xml"); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /Wrappers/ToolWrapper.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System.Collections.Generic; 4 | using System.Net.Http; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Facturapi.Wrappers 9 | { 10 | public class ToolWrapper : BaseWrapper 11 | { 12 | public ToolWrapper(string apiKey, string apiVersion = "v2") : base(apiKey, apiVersion) 13 | { 14 | } 15 | 16 | public async Task ValidateTaxId(string taxId) 17 | { 18 | var response = await client.GetAsync(Router.ValidateTaxId( 19 | new Dictionary() 20 | { 21 | ["tax_id"] = taxId 22 | } 23 | )); 24 | var resultString = await response.Content.ReadAsStringAsync(); 25 | 26 | if (!response.IsSuccessStatusCode) 27 | { 28 | var error = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 29 | throw new FacturapiException(error["message"].ToString()); 30 | } 31 | 32 | var result = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 33 | return result; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Wrappers/WebhookWrapper.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Linq; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Net.Http; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Facturapi.Wrappers 10 | { 11 | public class WebhookWrapper : BaseWrapper 12 | { 13 | public WebhookWrapper(string apiKey, string apiVersion = "v2") : base(apiKey, apiVersion) 14 | { 15 | } 16 | 17 | public async Task> ListAsync(Dictionary query = null) 18 | { 19 | var response = await client.GetAsync(Router.ListWebhooks(query)); 20 | var resultString = await response.Content.ReadAsStringAsync(); 21 | 22 | if (!response.IsSuccessStatusCode) 23 | { 24 | var error = JsonConvert.DeserializeObject(resultString); 25 | throw new FacturapiException(error["message"].ToString()); 26 | } 27 | 28 | var searchResult = JsonConvert.DeserializeObject>(resultString, this.jsonSettings); 29 | return searchResult; 30 | } 31 | 32 | public async Task CreateAsync(Dictionary data) 33 | { 34 | var response = await client.PostAsync(Router.CreateWebhook(), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 35 | var resultString = await response.Content.ReadAsStringAsync(); 36 | if (!response.IsSuccessStatusCode) 37 | { 38 | var error = JsonConvert.DeserializeObject(resultString); 39 | throw new FacturapiException(error["message"].ToString()); 40 | } 41 | var webhook = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 42 | return webhook; 43 | } 44 | 45 | public async Task RetrieveAsync(string id) 46 | { 47 | var response = await client.GetAsync(Router.RetrieveWebhook(id)); 48 | var resultString = await response.Content.ReadAsStringAsync(); 49 | if (!response.IsSuccessStatusCode) 50 | { 51 | var error = JsonConvert.DeserializeObject(resultString); 52 | throw new FacturapiException(error["message"].ToString()); 53 | } 54 | var webhook = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 55 | return webhook; 56 | } 57 | 58 | public async Task UpdateAsync(string id, Dictionary data) 59 | { 60 | var response = await client.PutAsync(Router.UpdateWebhook(id), new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 61 | var resultString = await response.Content.ReadAsStringAsync(); 62 | if (!response.IsSuccessStatusCode) 63 | { 64 | var error = JsonConvert.DeserializeObject(resultString); 65 | throw new FacturapiException(error["message"].ToString()); 66 | } 67 | var webhook = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 68 | return webhook; 69 | } 70 | 71 | public async Task DeleteAsync(string id) 72 | { 73 | var response = await client.DeleteAsync(Router.DeleteWebhook(id)); 74 | var resultString = await response.Content.ReadAsStringAsync(); 75 | if (!response.IsSuccessStatusCode) 76 | { 77 | var error = JsonConvert.DeserializeObject(resultString); 78 | throw new FacturapiException(error["message"].ToString()); 79 | } 80 | var webhook = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 81 | return webhook; 82 | } 83 | 84 | public async Task ValidateSignatureAsync(Dictionary data) 85 | { 86 | var response = await client.PostAsync(Router.ValidateSignature(),new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")); 87 | var resultString = await response.Content.ReadAsStringAsync(); 88 | if (!response.IsSuccessStatusCode) 89 | { 90 | var error = JsonConvert.DeserializeObject(resultString); 91 | throw new FacturapiException(error["message"].ToString()); 92 | } 93 | var webhook = JsonConvert.DeserializeObject(resultString, this.jsonSettings); 94 | return webhook; 95 | } 96 | 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /facturapi-net.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0;net452;net6.0;net8.0 5 | Facturapi 6 | Facturapi 7 | Facturapi 8 | Javier Rosas 9 | icon.png 10 | Genera facturas electrónicas válidas en México (CFDI) lo más fácil posible. Obtén tus 11 | API Keys creando una cuenta gratuita en https://www.facturapi.io 12 | factura factura-electronica cfdi facturapi mexico conekta 13 | Facturapi 14 | 4.8.0 15 | $(Version) 16 | Facturapi 17 | facturapi.ico 18 | True 19 | Facturación Espacial 20 | Facturación Espacial © 2025 21 | www.facturapi.io 22 | README.md 23 | https://github.com/facturapi/facturapi-net 24 | git 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /facturapi-net.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 17 3 | VisualStudioVersion = 17.8.34322.80 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "facturapi-net", "facturapi-net.csproj", "{11E14BFA-6A9B-43D6-828F-B493E1617326}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Any CPU = Debug|Any CPU 10 | Release|Any CPU = Release|Any CPU 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {11E14BFA-6A9B-43D6-828F-B493E1617326}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 14 | {11E14BFA-6A9B-43D6-828F-B493E1617326}.Debug|Any CPU.Build.0 = Debug|Any CPU 15 | {11E14BFA-6A9B-43D6-828F-B493E1617326}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | {11E14BFA-6A9B-43D6-828F-B493E1617326}.Release|Any CPU.Build.0 = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(SolutionProperties) = preSolution 19 | HideSolutionNode = FALSE 20 | EndGlobalSection 21 | GlobalSection(ExtensibilityGlobals) = postSolution 22 | SolutionGuid = {CD724334-BBC7-429A-907D-D09644F4444F} 23 | EndGlobalSection 24 | EndGlobal 25 | -------------------------------------------------------------------------------- /facturapi.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FacturAPI/facturapi-net/5f57ca0ddf05e63562c227a46da565eb47bab349/facturapi.ico -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FacturAPI/facturapi-net/5f57ca0ddf05e63562c227a46da565eb47bab349/icon.png --------------------------------------------------------------------------------