A .NET wrapper for the PAYMILL API.
- If you are not familiar with PAYMILL, start with the documentation.
- Install the latest release.
- Check the samples.
- Check the API reference.
- Check the additional documentation.
- Check the tests.
To install Wrapper for the PAYMILL API, run the following command in the Package Manager Console
PM> Install-Package PaymillWrapper
More info here
Download the lastest stable release from https://paymill.codeplex.com/releases.
We have released version 2. This version is not backwards compatible with version 1. Concrete changes in the changelog.
Initialize the library by providing your api key:
PaymillContext paymillContext = new PaymillContext( "<YOUR PRIVATE API KEY>" );
PaymillContext loads the context of PAYMILL for a single account, by providing a merchants private key. It creates 8 services, which represents the PAYMILL API:
- ClientService
- OfferService
- PaymentService
- PreauthorizationService
- RefundService
- SubscriptionService
- TransactionService
- WebhookService
These services should not be created directly. They have to be obtained by the context's accessors.
This library is based on asynchronous programming in .NET. All service calls returns Task.You use Task if no meaningful value is returned when the method is completed. If you're new to asynchronous programming or do not understand how an async method uses the await keyword to do potentially long-running work without blocking the caller’s thread, you should read the introduction in Asynchronous Programming with Async and Await (C# and Visual Basic).
To get the result of asynchronous task jut call .Result, more about Task and how it Return Types Async Return Types (C# and Visual Basic)
In all cases, you'll use the predefined service classes to access the PAYMILL API.
To fetch a service instance, call service name from paymillContext, like
ClientService clientService = paymillContext.ClientService;
Every service instance provides basic methods for CRUD functionality.
Every service provides instance factory methods for creation. They are very different for every service, because every object can be created in a different way. The common pattern is
xxxService.CreateXXX( params... );
For example: client can be created with two optional parameters: email and description. So we have four possible methods to create the client:
- clientService.CreateAsync() - creates a client without email and description
- clientService.CreateWithEmailAsync( "john.rambo@paymill.com" ) - creates a client with email
- clientService.CreateWithDescriptionAsync( "CRM Id: fake_34212" ) - creates a client with description
- clientService.CreateWithEmailAndDescriptionAsync( "john.rambo@paymill.com", "CRM Id: fake_34212" ) - creates a client with email and description
You can retrieve an object by using the get() method with an object id:
Task<Client> client = clientService.GetAsync( "client_12345" );
or with the instance itself, which also refreshes it:
clientService.GetAsync( client );
This method throws an ApiException if there is no client under the given id.
To retrieve a list you may simply use the list() method:
PaymillList<Client> clients = clientService.ListAsync().Result;
You may provide a filter and order to list method:
PaymillList<Client> clients =
clientService.ListAsync(
Client.CreateFilter().ByEmail( "john.rambo@paymill.com" ),
Client.CreateOrder().ByCreatedAt().Desc()
).Result;
This will load only clients with email john.rambo@paymill.com, order descending by creation date.
In order to update an object simply call a service's update() method:
clientServive.UpdateAsync( client );
The update method also refreshes the the given instance. For example: If you changed the value of 'CreatedAt' locally and pass the instance to the Update() method, it will be refreshed with the data from PAYMILL. Because 'CreatedAt' is not updateable field your change will be lost.
You may delete objects by calling the service's delete() method with an object instance or object id.
clientService.DeleteAsync( "client_12345" );
or
clientService.DeleteAsync( client );
- Change library to asynchronous programming.
- Add factory methods for all objects.
- Clear object's models.
- Add 'Updatable' attribute.
- Add custom JSON converters.
- Add filters and orders.
- Hide API url.
- Change all enums to EnumBaseType.
- Merge with digitalcreations / paymillsharp
- Add source field and Status for Preauthorization.
- Add currency and billed_at to the Fee model.
Create library.
To contribute to the wrapper, please fork it and create a pull request.
Thanks to:
- jcantos for the original wrapper.
- digitalcreations for the core changes for v2.
- all contributors
Copyright 2013 PAYMILL GmbH.
MIT License (enclosed)