• Stars
    star
    108
  • Rank 320,421 (Top 7 %)
  • Language
    PHP
  • License
    Other
  • Created over 11 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Handles currency calculations, storage etc

Currency Package

Build Status

The Moltin currency composer package makes it easy to implement multi-currency pricing into your application and store the exchange data using one of the numerous data stores provided. You can also inject your own data store if you would like your data to be stored elsewhere.

Installation

Download and install composer from http://www.getcomposer.org/download

Add the following to your project composer.json file

{
    "require": {
        "moltin/currency": "~1.0.0"
    }
}

When you're done just run php composer.phar install and the package is ready to be used.

Usage

Below is a basic usage guide for this package.

Instantiating currency

Before you begin, you will need to know which storage, currencies and exchange method you are going to use. The exchange method defines where your exchange rates are retrieved from. The currencies method is used to retrieve your supported currencies for the current application.

In this example we're going to use the currencies file, exchange file and session for storage.

use Moltin\Currency\Currency as Currency;
use Moltin\Currency\Format\Runtime as RuntimeFormat;
use Moltin\Currency\Exchange\OpenExchangeRates as OpenExchange;

$currency = new Currency(new OpenExchange($app_id), new RuntimeFormat);

Setting the value

Now that you have Currency instantiated, you will now need to tell it what value you would like to convert. You can do this using the following method.

$currency->convert(9.33)->from('GBP');

Getting the value

The most basic action you can perform is retrieve the original value back from the method.

// Returns 9.33
$value = $currency->value();

Formatting as a currency

By default the currency is set to GBP so calling currency will format the value to a string with £ and correct decimal and thousand seperators.

// Returns £9.33
$value = $currency->format();

Rounding to common values

There are a number of common pricing formats built in to make "nice" prices easy to implement. These formats changes the default value and return the object to allow for chaining.

// Sets value to 10.00
$currency->zeros();

// Sets value to 9.99
$currency->nines();

// Sets value to 9.50
$currency->fifty();

// Returns £9.50
$value = $currency->fifty()->format();

Currency Exchange

The package makes it as easy as possible to quickly switch between currencies. Before each exchange the value is reset to default to ensure the correct price is assigned.

// Returns ~$14.47
$value = $currency->convert(9.33)->from('GBP')->to('USD')->format();

// Returns ~14.50
$value = $currency->convert(9.33)->from('GBP')->to('USD')->fifty()->value();

Resetting the value

After using exchange or any of the rounding functions to retrieve the default value you must call reset.

// Returns 10.00
$value = $currency->zeros()->value();

// Returns 9.33
$value = $currency->reset()->value();

More Repositories

1

laravel-cart

Laravel Facade and Service Provider for Moltin\Cart
PHP
276
star
2

react-demo-store

Moltin + React powered online store
JavaScript
195
star
3

js-sdk

JavaScript & Node.js SDKs for the Elastic Path Commerce Cloud eCommerce API
TypeScript
173
star
4

cart

Shopping cart composer package
PHP
110
star
5

nextjs-demo-store

🛍 Moltin powered Next.js storefront
JavaScript
101
star
6

gatsby-demo-store

Elastic Path + Gatsby powered online store
JavaScript
93
star
7

php-sdk

Community built SDK for using Moltin with PHP
PHP
47
star
8

ios-sdk

Swift SDK for the Moltin eCommerce API
Swift
37
star
9

shopkit

Powerful, embeddable cart and checkout.
JavaScript
30
star
10

vue-demo-store

JavaScript
27
star
11

ios-swift-example

A Swift demo app using the Moltin iOS SDK.
Swift
23
star
12

gatsby-source-moltin

🚀 Gatsby source plugin for building Elastic Path Commerce Cloud powered eCommerce websites
JavaScript
21
star
13

framework

Lightweight store framework built using Slim, Twig, Bootstrap and the Moltin SDK.
CSS
19
star
14

moltin-request

🎮 Minimal Elastic Path Commerce Cloud API request library for Node
TypeScript
17
star
15

ruby-sdk

Moltin Ruby SDK
Ruby
16
star
16

examples

⚡️ Collection of examples using the Moltin API
JavaScript
16
star
17

terraform-stack

A group of more formulated Terraform modules
HCL
13
star
18

nextjs-tutorial-code

JavaScript
12
star
19

react-redux-moltin-boilerplate

boilerplate setup for a moltin store built in react + redux
JavaScript
12
star
20

moltin-micro-checkout

💳 One-click moltin purchase with Stripe
JavaScript
10
star
21

redis-scripts

Script to maintain Redis databases
Shell
9
star
22

react-microsite

🛍 Moltin powered microsite built with Create React App & Shopkit
JavaScript
9
star
23

swift-demo-app

An eCommerce example App in swift
Swift
7
star
24

menagerie

Serverless image resizing, manipulation, and optimzation S3 proxy
TypeScript
7
star
25

terraform-rancher-ha

Terraform Rancher HA cluster in AWS
HCL
7
star
26

python-sdk

Moltin python SDK
Python
6
star
27

android-sdk

Java
6
star
28

lua-multipart-parser

A simple HTTP multipart encoder/decoder for Lua
Lua
6
star
29

ios-objc-example

An Objective-C demo app using the Moltin iOS SDK.
Objective-C
6
star
30

terraform-modules

A group of base Terraform modules
HCL
6
star
31

docs.moltin.com

6
star
32

ios-swift-tutorial

A getting started with Swift tutorial for the Moltin iOS eCommerce SDK.
Swift
5
star
33

android-example

Java
5
star
34

integration-server-example-php

A small example of an integration server written in PHP to demonstrate the usage of moltin integration webhooks
PHP
5
star
35

tax

Tax calculations for Moltin\Cart
PHP
4
star
36

progressive-web-app

Example commerce app using Ionic and Angular 2
JavaScript
3
star
37

developers.moltin.com

3
star
38

moltin-next-checkout

⚡️ Next.js demo for one-click moltin purchasing
JavaScript
3
star
39

csharp-sdk

C# API interface and SDK
C#
2
star
40

node-demo-store

JavaScript
2
star
41

applepayexample-completed

This is the a completed project for the apple pay demo guide. https://developers.moltin.com/guides/apple-google-pay
Swift
2
star
42

moltin-product-importer

Import products from a CSV into Moltin though the API
JavaScript
2
star
43

cordova-square-reader

A Cordova plugin to interface with the native Square Reader SDK libraries.
Swift
2
star
44

transfer-flow-data

Serverless function to pass flow data from cart items on to order items
JavaScript
1
star
45

apple-pay-swift-tutorial

A getting started with Apple Pay tutorial for the Moltin iOS eCommerce SDK, written in Swift.
Swift
1
star
46

tf_azure_public_ip

A Terraform module to provide a Public IP on Microsoft Azure.
HCL
1
star
47

v2-import

A quick n dirty PHP import script for products & categories in v2
PHP
1
star
48

ansible-rancher-agent

Ansible role to register host to our Rancher server
Shell
1
star
49

moltin-stripe-paymentintents

💳 SCA compliant payments with Moltin and Stripe
JavaScript
1
star
50

moltin-paymentrequest-api

💳 Demoing the Payment Request API with moltin
JavaScript
1
star
51

moltin-shippo-rates

📦 Get shipping rates for orders by Shippo for your moltin store
JavaScript
1
star
52

ios-getting-started-tutorial

A getting started tutorial for the Moltin iOS eCommerce SDK.
Objective-C
1
star
53

moltin-shippo-tracking

📦 Update orders via a webhook with a delivery status by Shippo
JavaScript
1
star