Git Product home page Git Product logo

visma's Introduction

Visma Application

Elixir implementation of Visma API.

Build

mix deps.get
mix compile

Test

mix eunit

Configuration

If you are using Visma.Manager application, you will need to configure these elements in config/config.exs

config :visma,
  base_url: "https://demo.vismaaddo.net/WebService/v2.0/restsigningservice.svc",
  email: "[email protected]",
  password: Base.decode64!("c/SjPSMTRcZW1yzcvs6qdUOrnx4GyHoH0fyD0h9XnAAYP7PP/sNgTjKDMSUGlZAXB+ZFmm20JWK6hrsgJHsGYw==")

Usage

When started, Visma application start a process called Visma.Manager. This one automatically generate a valid token and can automatically renew it when sending requests. The implementation is not complete, all requests are not managed by this process at the moment.

High Level Usage (with Visma.Manager)

Here some code example to use it with Visma.Manager.

# Manually start Visma.Manager. This process
# is registered.
{:ok, pid} = Visma.Manager.start_link()

# Get the current token assigned to the manager.
Visma.Manager.get_token()

# Get all templates availables.
Visma.Manager.get_signing_templates()

# Get all availables templates sorted by id (Id field)
Visma.Manager.get_signing_templates_by_id()

# Get all availables templates sorted by name
# (FriendlyName field)
Visma.Manager.get_signing_templates_by_name()

Low Level Usage (with Visma.Api)

This application can also be used as a library. Here an example to initiate a new signature. At first, a token is required.

# A token is required when we do a request. If
# Visma.Manager is started, we can also call
# Visma.Manager.get_token().
{:ok, token} = Visma.Api.new()
|> Visma.Api.login(
    email: "[email protected]",
    password: "mypassword"
)
|> Visma.Api.send()

A signing request is required as well.

# First, we generate a signing data-structure
signing_request = Visma.Signing.new()

# A request has mandatory parameters, like its name
# but also a reference numbeder and a valid signing
# template id (you can find it using
# Manager.Visma.get_signing_templates)
|> Visma.Signing.request(
    name: "my signing request name",
    reference_number: "12345",
    signing_template_id: "valid-signing-template-id"
)

# Next, we can configure a new sender.
|> Visma.Signing.sender(
    name: "My Sender Name",
    company_name: "My Company Name",
    email: "[email protected]",
    phone: "My Phone"
)

# Next, we can set one or many recipients. A
# valid name and CPR number are mandatory.
|> Visma.Signing.recipient(
    name: "John Doe",
    cpr: "1234567890",
    email: "[email protected]"
)
|> Visma.Signing.recipient(
    name: "John Smith",
    cpr: "2345678901",
    email: "[email protected]"
)

# Finally, we can now set the attachments/documents
# to send to Visma. Visma only support `application/pdf`
# mime type, so, this is the default set if not
# present.
|> Visma.Signing.document(
    name: "billing.pdf",
    data: File.read!("billing.pdf"),
    mime_type: "application/pdf"
)

When the request is ready, 2 methods can be used to send the request. The first one is using only Visma.deliver/1 function. This function deal with required token and other objects.

Visma.deliver(signing_request)

Or using Visma.Api.send/1 function. This method is more complex but it is a low level way.

# Create a new Visma API request
Visma.Api.new()

# Set it with to deal with a new signing process
# signing_request parameter must be map()
|> Visma.Api.initiate_signing(
    token: token,
    signing_request: Visma.Signing.to_map(signing_request)
)

# Send the request
|> Visma.Api.send()

References and Resources

visma's People

Contributors

kfmak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.