Skip to content

Commit

Permalink
Use GooglePayResult in SourceParams.createCardParamsFromGooglePay() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mshafrir-stripe authored Nov 22, 2019
1 parent fabbbe2 commit a7075d8
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 deletions stripe/src/main/java/com/stripe/android/model/SourceParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import androidx.annotation.IntRange
import androidx.annotation.Size
import com.stripe.android.model.Source.Companion.asSourceType
import com.stripe.android.model.Source.SourceType
import com.stripe.android.model.StripeJsonUtils.optString
import com.stripe.android.model.Token.Companion.fromJson
import java.util.Objects
import org.json.JSONException
import org.json.JSONObject
Expand Down Expand Up @@ -676,43 +674,15 @@ class SourceParams private constructor(
fun createCardParamsFromGooglePay(
googlePayPaymentData: JSONObject
): SourceParams {
val paymentMethodData = googlePayPaymentData
.getJSONObject("paymentMethodData")
val googlePayBillingAddress = paymentMethodData
.getJSONObject("info")
.optJSONObject("billingAddress")
val paymentToken = paymentMethodData
.getJSONObject("tokenizationData")
.getString("token")
val stripeToken = fromJson(JSONObject(paymentToken))
val stripeTokenId = requireNotNull(stripeToken).id
val googlePayResult = GooglePayResult.fromJson(googlePayPaymentData)
val params = SourceParams(SourceType.CARD)
.setToken(stripeTokenId)
val address: Address?
val phone: String?
val name: String?
if (googlePayBillingAddress != null) {
name = optString(googlePayBillingAddress, "name")
phone = optString(googlePayBillingAddress, "phoneNumber")
address = Address.Builder()
.setLine1(optString(googlePayBillingAddress, "address1"))
.setLine2(optString(googlePayBillingAddress, "address2"))
.setCity(optString(googlePayBillingAddress, "locality"))
.setState(optString(googlePayBillingAddress, "administrativeArea"))
.setPostalCode(optString(googlePayBillingAddress, "postalCode"))
.setCountry(optString(googlePayBillingAddress, "countryCode"))
.build()
} else {
name = null
phone = null
address = null
}
.setToken(requireNotNull(googlePayResult.token?.id))
return params.setOwner(
Owner(
address = address,
email = optString(googlePayPaymentData, "email"),
name = name,
phone = phone
address = googlePayResult.address,
email = googlePayResult.email,
name = googlePayResult.name,
phone = googlePayResult.phoneNumber
).toParamMap()
)
}
Expand Down

0 comments on commit a7075d8

Please sign in to comment.