scala-stripe


License

License

MIT
Categories

Categories

Scala Languages Stripe Business Logic Libraries Financial
GroupId

GroupId

com.outr
ArtifactId

ArtifactId

scala-stripe_2.13
Last Version

Last Version

1.1.11
Release Date

Release Date

Type

Type

jar
Description

Description

scala-stripe
scala-stripe
Project URL

Project URL

https://github.com/outr/scala-stripe
Project Organization

Project Organization

com.outr
Source Code Management

Source Code Management

https://github.com/outr/scala-stripe

Download scala-stripe_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/com.outr/scala-stripe_2.13/ -->
<dependency>
    <groupId>com.outr</groupId>
    <artifactId>scala-stripe_2.13</artifactId>
    <version>1.1.11</version>
</dependency>
// https://jarcasting.com/artifacts/com.outr/scala-stripe_2.13/
implementation 'com.outr:scala-stripe_2.13:1.1.11'
// https://jarcasting.com/artifacts/com.outr/scala-stripe_2.13/
implementation ("com.outr:scala-stripe_2.13:1.1.11")
'com.outr:scala-stripe_2.13:jar:1.1.11'
<dependency org="com.outr" name="scala-stripe_2.13" rev="1.1.11">
  <artifact name="scala-stripe_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.outr', module='scala-stripe_2.13', version='1.1.11')
)
libraryDependencies += "com.outr" % "scala-stripe_2.13" % "1.1.11"
[com.outr/scala-stripe_2.13 "1.1.11"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.3
org.scalactic : scalactic_2.13 jar 3.2.1
io.youi : youi-client_2.13 jar 0.13.16

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.2.1

Project Modules

There are no modules declared in this project.

scala-stripe

Codacy Badge Build Status Stories in Ready Gitter Maven Central Latest version

Provides both client (Stripe.js using Scala.js) and server (NIO Scala) functionality for dealing with Stripe.

For more information on the Stripe API see https://stripe.com/docs/api

For more information on Stripe.js see https://stripe.com/docs/stripe.js

SBT Configuration

scala-stripe is published to Sonatype OSS and Maven Central and supports JVM and Scala.js with 2.11 and 2.12:

libraryDependencies += "com.outr" %% "scala-stripe" % "1.1.11"   // Scala
libraryDependencies += "com.outr" %%% "scala-stripe" % "1.1.11"  // Scala.js / Cross-Build

Dependencies

It's important to know how much your biting off when you are adding another dependency to your project. As such, we've endeavored to keep the dependencies to a minimum:

Getting Started

Though the JVM supports creating credit card tokens, the ideal path is to avoid the server ever having any such knowledge. To that end we will use Scala.js to first create the card token, and then the server (JVM) will use that token to make a purchase.

In the Browser

Setting up Stripe.js

We must first set our publishable key. Make sure you are using the public key (starts with "pk_"):

Stripe.setPublishableKey(stripePublicKey)

Validating the credit card

val validationResult: Boolean = Stripe.card.validateCardNumber(creditCardNumber)

Creating a Stripe Token for the credit card

The following example is a basic use-case, and assumes you'll provide implementations of sending the token to the server as well as showing token failure messages as that information is specific to your implementation.

Stripe.card.createToken(new StripeCardInfo {
  number = creditCardNumber
  exp_month = cardExpirationMonth
  exp_year = cardExpirationYear
}, (status: Int, info: CardTokenInfo) => {
  if (status == 200) {
    sendCardTokenInfoToServer(info.id, ...other useful information the server might need...)
  } else {
    showCardTokenFailure(info.error)
  }
})

On the Server

Creating a Stripe instance

As discussed in the Browser section, we have two keys: public ("pk_") and secret ("sk_"). For the server to work with Stripe we should use our private key to create an instance of Stripe:

val stripe = new Stripe(stripePrivateKey)

Charging the Credit Card

Now that we have received the card token on the server, we can use that to make a purchase with Stripe:

stripe.charges.create(Money(5.0), "USD", source = creditCardTokenId, customer = customerId).map {
  case Left(failure) => // Handle error from Stripe server
  case Right(charge) => // Success! Handle the Charge instance returned
}

Next Steps

Hopefully that is enough to get you started with stripe-scala. There is much more available and we attempt to be a very close wrapper around the Stripe API. If you have any problems refer to the Stripe API documentation as we try to remain very close to them.

Features for 2.0.0 (In-Progress)

  • Stripe API Relay
    • Orders
    • Order Items
    • Returns
    • Products
    • SKUs
  • Stripe API Radar
    • Reviews
  • Stripe API Core Resources
    • File Uploads
  • Stripe API Payments
    • Alipay Accounts
    • Sources
  • Stripe.js
    • Apple Pay

Features for 1.1.0 (Released 2017.08.08)

  • Migration to youi-client away from Gigahorse
  • Better error handling support

Features for 1.0.0 (Released 2016.01.05)

  • Stripe.js functionality in Scala.js (Excludes Apple Pay)
    • Card
    • Bank Account
    • Personally Identifiable Information (PII)
  • Stripe API Core Resources
    • Balance
    • Charges
    • Customers
    • Disputes
    • Events
    • Refunds
    • Tokens
    • Transfers
    • Transfer Reversals
  • Stripe API Connect
    • Account
    • Application Fees
    • Application Fee Refunds
    • Country Specs
    • External Accounts
  • Stripe API Payments
    • Bank Accounts
    • Cards
  • Stripe API Subscriptions
    • Coupons
    • Discounts
    • Invoices
    • Invoice Items
    • Plans
    • Subscriptions
com.outr

OUTR Technologies

Versions

Version
1.1.11