Skip to content

Commit

Permalink
Merge pull request #277 from ostelco/feature/payment-list-sources-add…
Browse files Browse the repository at this point in the history
…-more-info

Adds more details about each souce/account/ to the 'list payment sources' client  API
  • Loading branch information
Kjell M. Myksvoll authored Sep 12, 2018
2 parents 4895f86 + 41def6d commit 56bc645
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 8 deletions.
Empty file modified acceptance-tests/script/wait.sh
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ class SourceTest {
assert(sources.isNotEmpty()) { "Expected at least one payment source for profile $email" }
assert(sources.map{ it.id }.containsAll(listOf(cardId, newCardId)))
{ "Expected to find both $cardId and $newCardId in list of sources for profile $email" }

sources.forEach {
assert(it.details.id.isNotEmpty()) { "Expected 'id' to be set in source account details for profile $email" }
assertEquals("card", it.details.accountType,
"Unexpected source account type ${it.details.accountType} for profile $email")
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ class SourceTest {
assert(sources.isNotEmpty()) { "Expected at least one payment source for profile $email" }
assert(sources.map{ it.id }.containsAll(listOf(cardId, newCardId)))
{ "Expected to find both $cardId and $newCardId in list of sources for profile $email" }

sources.forEach {
assert(it.details.id.isNotEmpty()) { "Expected 'id' to be set in source account details for profile $email" }
assertEquals("card", it.details.accountType,
"Unexpected source account type ${it.details.accountType} for profile $email")
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ package org.ostelco.prime.paymentprocessor

import arrow.core.Either
import arrow.core.flatMap
import com.stripe.model.Charge
import com.stripe.model.Customer
import com.stripe.model.Plan
import com.stripe.model.Product
import com.stripe.model.Subscription
import org.ostelco.prime.logger
import com.stripe.model.Refund
import com.stripe.model.*
import org.ostelco.prime.paymentprocessor.core.*


Expand All @@ -21,11 +16,42 @@ class StripePaymentProcessor : PaymentProcessor {
val sources = mutableListOf<SourceInfo>()
val customer = Customer.retrieve(customerId)
customer.sources.data.forEach {
sources.add(SourceInfo(it.id))
sources.add(SourceInfo(it.id, getAccountDetails(it)))
}
sources
}

/* Returns detailed 'account details' for the given Stripe source/account.
Note that the fields 'id' and 'accountType' are manadatory. */
private fun getAccountDetails(accountInfo: ExternalAccount) : Map<String, Any> {
when (accountInfo) {
is Card -> {
return mapOf("id" to accountInfo.id,
"accountType" to "card",
"addressLine1" to accountInfo.addressLine1,
"addressLine2" to accountInfo.addressLine2,
"zip" to accountInfo.addressZip,
"city" to accountInfo.addressCity,
"state" to accountInfo.addressState,
"country" to accountInfo.country,
"currency" to accountInfo.currency,
"brand" to accountInfo.brand, // "Visa", "Mastercard" etc.
"last4" to accountInfo.last4,
"expireMonth" to accountInfo.expMonth,
"expireYear" to accountInfo.expYear,
"funding" to accountInfo.funding) // Typ.: "credit" or "debit"
.filterValues { it != null } // Unfortunately the 'swagger' def. will removed fields back again.
}
// To add support for other Stripe source/account types, see
// https://stripe.com/docs/api/java#sources
else -> {
logger.error("Received unsupported Stripe source/account type: {}", accountInfo)
return mapOf("id" to accountInfo.id,
"accountType" to "unsupported")
}
}
}

override fun createPaymentProfile(userEmail: String): Either<PaymentError, ProfileInfo> =
either(ForbiddenError("Failed to create profile for user $userEmail")) {
val customerParams = mapOf("email" to userEmail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class ProductInfo(val id: String)

class ProfileInfo(val id: String)

class SourceInfo(val id: String)
class SourceInfo(val id: String, val details: Map<String, Any>? = null)

class SubscriptionInfo(val id: String)
35 changes: 35 additions & 0 deletions prime/infra/dev/prime-client-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,41 @@ definitions:
id:
description: "The identifier for the source"
type: string
details:
description: "All information stored with the source"
type: object
properties:
id:
type: string
accountType:
type: string
addressLine1:
type: string
addressLine2:
type: string
zip:
type: string
city:
type: string
state:
type: string
country:
type: string
currency:
type: string
brand:
type: string
last4:
type: string
expireMonth:
type: integer
expireYear:
type: integer
funding:
type: string
required:
- id
- accountType
ConsentList:
type: array
items:
Expand Down

0 comments on commit 56bc645

Please sign in to comment.