Skip to content

Commit

Permalink
Merge pull request #1 from riveramj/resuscitation
Browse files Browse the repository at this point in the history
Updated the api version to 2016-03-07 and ensures tests pass with new json test data that correlates to the API version.
  • Loading branch information
farmdawgnation committed Apr 3, 2016
2 parents aa5f82e + 7560e8c commit 7de7d42
Show file tree
Hide file tree
Showing 16 changed files with 441 additions and 308 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ project/plugins/project/
# Scala-IDE specific
.scala_dependencies
.worksheet
*.swp
*.swo
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ By default, the StripeExecutor will be locked to the version of the API that the
is tested against. If you want to change that you could declare your executor like so:

```scala
implicit val e = new StripeExecutor("myapikey", apiVersion = "2014-12-22")
implicit val e = new StripeExecutor("myapikey", apiVersion = "2016-03-07")
```

That would lock your app to the 2014-12-22 version of the API regardless of what the version of the
That would lock your app to the 2016-03-07 version of the API regardless of what the version of the
library you're using wants. *Please be aware this could cause things to break.* If for some reason
we're not pulling out data that you need from the JSON that Stripe sends us, you can get a copy of
that represented as a Lift JValue by setting the `includeRaw` parameter on the executor to true.
Expand Down
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ version := "0.0.4-SNAPSHOT"

organization := "me.frmr.stripe"

scalaVersion := "2.11.4"
scalaVersion := "2.11.8"

resolvers += "Farmdawg Temp Forks" at "http://dl.bintray.com/farmdawgnation/temp-forks"

libraryDependencies ++= {
val liftVersion = "2.6-RC1"
val liftVersion = "2.6.3"
Seq(
"net.liftweb" %% "lift-common" % liftVersion,
"net.liftweb" %% "lift-util" % liftVersion,
"net.liftweb" %% "lift-json" % liftVersion,
"net.databinder.dispatch" %% "dispatch-core" % "0.11.2",
"net.databinder.dispatch" %% "dispatch-lift-json" % "0.11.2",
"org.scalatest" %% "scalatest" % "2.2.1" % "test"
"net.databinder.dispatch" %% "dispatch-core" % "0.11.3",
"net.databinder.dispatch" %% "dispatch-lift-json" % "0.11.3",
"org.scalatest" %% "scalatest" % "2.2.6" % "test"
)
}

Expand Down
1 change: 0 additions & 1 deletion src/main/scala/me/frmr/stripe/Account.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ case class Account(
id: String,
chargesEnabled: Boolean,
country: String,
currenciesSupported: List[String],
defaultCurrency: String,
detailsSubmitted: Boolean,
transfersEnabled: Boolean,
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/me/frmr/stripe/Customer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import dispatch._, Defaults._
case class Customer(
id: String,
livemode: Boolean,
cards: CardList,
sources: CardList,
created: Long,
accountBalance: Long,
currency: String,
delinquent: Boolean,
defaultCard: Option[String],
defaultSource: Option[String],
description: Option[String],
discount: Option[Discount],
email: Option[String],
Expand Down Expand Up @@ -63,7 +63,7 @@ object Customer extends Listable[CustomerList] with Gettable[Customer] with Dele
id: String,
accountBalance: Option[String] = None,
card: Option[String] = None,
defaultCard: Option[String] = None,
defaultSource: Option[String] = None,
coupon: Option[String] = None,
description: Option[String] = None,
email: Option[String] = None,
Expand All @@ -73,7 +73,7 @@ object Customer extends Listable[CustomerList] with Gettable[Customer] with Dele
accountBalance.map(("account_balance", _)),
card.map(("card", _)),
coupon.map(("coupon", _)),
defaultCard.map(("default_card", _)),
defaultSource.map(("default_source", _)),
description.map(("description", _)),
email.map(("email", _))
).flatten.toMap ++ metadataProcessor(metadata)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/me/frmr/stripe/StripeExecutor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object AsStripeResponse extends (Response=>StripeResponse) {
class StripeExecutor(
apiKey: String,
includeRaw: Boolean = false,
apiVersion: String = "2014-12-22"
apiVersion: String = "2016-03-07"
) {
val httpExecutor = new Http()
val baseReq = url("https://api.stripe.com/v1").secure.as(apiKey, "") <:< Map("Stripe-Version" -> apiVersion)
Expand Down
143 changes: 130 additions & 13 deletions src/test/scala/me/frmr/stripe/AccountSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,140 @@ class AccountSpec extends WordSpec with ShouldMatchers {
val json = """
{
"id": "acct_1032D82eZvKYlo2C",
"object": "account",
"business_logo": null,
"business_name": "Stripe.com",
"business_url": null,
"charges_enabled": false,
"country": "US",
"debit_negative_balances": true,
"decline_charge_on": {
"avs_failure": false,
"cvc_failure": false
},
"default_currency": "usd",
"details_submitted": false,
"display_name": "Stripe.com",
"email": "site@stripe.com",
"external_accounts": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/accounts/acct_1032D82eZvKYlo2C/external_accounts"
},
"legal_entity": {
"additional_owners": null,
"address": {
"city": null,
"country": "US",
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"address_kana": {
"city": null,
"country": "US",
"line1": null,
"line2": null,
"postal_code": null,
"state": null,
"town": null
},
"address_kanji": {
"city": null,
"country": "US",
"line1": null,
"line2": null,
"postal_code": null,
"state": null,
"town": null
},
"business_name": null,
"business_name_kana": null,
"business_name_kanji": null,
"business_tax_id_provided": false,
"dob": {
"day": null,
"month": null,
"year": null
},
"first_name": null,
"first_name_kana": null,
"first_name_kanji": null,
"gender": null,
"last_name": null,
"last_name_kana": null,
"last_name_kanji": null,
"maiden_name": null,
"personal_address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"personal_address_kana": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null,
"town": null
},
"personal_address_kanji": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null,
"town": null
},
"personal_id_number_provided": false,
"phone_number": null,
"ssn_last_4_provided": false,
"type": null,
"verification": {
"details": null,
"details_code": "failed_other",
"document": null,
"status": "unverified"
}
},
"managed": false,
"product_description": null,
"statement_descriptor": null,
"display_name": "Stripe.com",
"support_email": null,
"support_phone": null,
"timezone": "US/Pacific",
"details_submitted": false,
"charges_enabled": false,
"tos_acceptance": {
"date": null,
"ip": null,
"user_agent": null
},
"transfer_schedule": {
"delay_days": 7,
"interval": "daily"
},
"transfers_enabled": false,
"currencies_supported": [
"usd",
"aed",
"afn"
],
"default_currency": "usd",
"country": "US",
"object": "account",
"business_name": "Stripe.com"
"verification": {
"disabled_reason": "fields_needed",
"due_by": null,
"fields_needed": [
"business_url",
"external_account",
"product_description",
"support_phone",
"tos_acceptance.date",
"tos_acceptance.ip"
]
}
}
"""

Expand All @@ -45,7 +163,6 @@ class AccountSpec extends WordSpec with ShouldMatchers {
testAccount.detailsSubmitted should equal(false)
testAccount.chargesEnabled should equal(false)
testAccount.transfersEnabled should equal(false)
testAccount.currenciesSupported(0) should equal("usd")
testAccount.defaultCurrency should equal("usd")
testAccount.country should equal("US")
testAccount.businessName should equal("Stripe.com")
Expand Down
30 changes: 20 additions & 10 deletions src/test/scala/me/frmr/stripe/BalanceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@ class BalanceSpec extends WordSpec with ShouldMatchers {
"retrieve correct fields from Stripe's JSON" in {
val exampleBalanceJson = """
{
"pending": [
{
"amount": 4966640,
"currency": "usd"
}
],
"object": "balance",
"available": [
{
"amount": -2352,
"currency": "usd"
{
"currency": "usd",
"amount": -2352,
"source_types": {
"card": 8032622669,
"bank_account": 8509784,
"bitcoin_receiver": 1449199
}
}
],
"livemode": false,
"object": "balance"
"pending": [
{
"currency": "usd",
"amount": 4966640,
"source_types": {
"card": 746697673,
"bank_account": 0,
"bitcoin_receiver": 0
}
}
]
}
"""

Expand Down
61 changes: 35 additions & 26 deletions src/test/scala/me/frmr/stripe/BalanceTransactionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,53 @@ class BalanceTransactionSpec extends WordSpec with ShouldMatchers {
"retrieve correct fields from Stripe's JSON" in {
val exampleJson = """
{
"id": "txn_15DRvX2eZvKYlo2CgxMQ25SQ",
"id": "txn_17bBwe2eZvKYlo2Cuwcyi9or",
"object": "balance_transaction",
"amount": 500,
"amount": 400,
"available_on": 1455235200,
"created": 1454687788,
"currency": "usd",
"net": 455,
"type": "charge",
"created": 1419476679,
"available_on": 1420070400,
"status": "pending",
"fee": 45,
"description": "Charge for test@example.com",
"fee": 42,
"fee_details": [
{
"amount": 45,
"currency": "usd",
"type": "stripe_fee",
"description": "Stripe processing fees",
"application": null
}
{
"amount": 42,
"application": null,
"currency": "usd",
"description": "Stripe processing fees",
"type": "stripe_fee"
}
],
"source": "ch_15DRvX2eZvKYlo2CzgFB69s3",
"description": null
"net": 358,
"source": "ch_17bBwe2eZvKYlo2Crk3VGEG8",
"sourced_transfers": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/transfers?source_transaction=ch_17bBwe2eZvKYlo2Crk3VGEG8"
},
"status": "pending",
"type": "charge"
}
"""

val testBalanceTransaction = camelifyFieldNames(parse(exampleJson)).extract[BalanceTransaction]

testBalanceTransaction.id should equal("txn_15DRvX2eZvKYlo2CgxMQ25SQ")
testBalanceTransaction.amount should equal(500)
testBalanceTransaction.id should equal("txn_17bBwe2eZvKYlo2Cuwcyi9or")
testBalanceTransaction.amount should equal(400)
testBalanceTransaction.currency should equal("usd")
testBalanceTransaction.net should equal(455)
testBalanceTransaction.net should equal(358)
testBalanceTransaction.`type` should equal("charge")
testBalanceTransaction.created should equal(1419476679)
testBalanceTransaction.availableOn should equal(1420070400)
testBalanceTransaction.created should equal(1454687788)
testBalanceTransaction.availableOn should equal(1455235200)
testBalanceTransaction.status should equal("pending")
testBalanceTransaction.fee should equal(45)
testBalanceTransaction.source should equal("ch_15DRvX2eZvKYlo2CzgFB69s3")
testBalanceTransaction.description should equal(None)
testBalanceTransaction.feeDetails(0).amount should equal(45)
testBalanceTransaction.fee should equal(42)
testBalanceTransaction.source should equal("ch_17bBwe2eZvKYlo2Crk3VGEG8")
testBalanceTransaction.description should equal(Some("Charge for test@example.com"))
testBalanceTransaction.feeDetails(0).amount should equal(42)
testBalanceTransaction.feeDetails(0).currency should equal("usd")
testBalanceTransaction.feeDetails(0).`type` should equal("stripe_fee")
testBalanceTransaction.feeDetails(0).description should equal(Some("Stripe processing fees"))
Expand Down
Loading

0 comments on commit 7de7d42

Please sign in to comment.