diff --git a/app/src/main/graphql/createOrUpdateBackingAddress.graphql b/app/src/main/graphql/createOrUpdateBackingAddress.graphql new file mode 100644 index 0000000000..6a07fe4015 --- /dev/null +++ b/app/src/main/graphql/createOrUpdateBackingAddress.graphql @@ -0,0 +1,5 @@ +mutation CreateOrUpdateBackingAddress($input: CreateOrUpdateBackingAddressInput!) { + createOrUpdateBackingAddress(input : $input) { + success + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kickstarter/mock/services/MockApolloClient.kt b/app/src/main/java/com/kickstarter/mock/services/MockApolloClient.kt index 9500ada2b3..cab3cc92ff 100644 --- a/app/src/main/java/com/kickstarter/mock/services/MockApolloClient.kt +++ b/app/src/main/java/com/kickstarter/mock/services/MockApolloClient.kt @@ -47,6 +47,7 @@ import com.kickstarter.services.apiresponses.updatesresponse.UpdatesGraphQlEnvel import com.kickstarter.services.mutations.CreateAttributionEventData import com.kickstarter.services.mutations.CreateBackingData import com.kickstarter.services.mutations.CreateCheckoutData +import com.kickstarter.services.mutations.CreateOrUpdateBackingAddressData import com.kickstarter.services.mutations.PostCommentData import com.kickstarter.services.mutations.SavePaymentMethodData import com.kickstarter.services.mutations.UpdateBackingData @@ -299,6 +300,10 @@ open class MockApolloClientV2 : ApolloClientTypeV2 { override fun createPaymentIntent(createPaymentIntentInput: CreatePaymentIntentInput): io.reactivex.Observable { return io.reactivex.Observable.empty() } + + override fun createOrUpdateBackingAddress(eventInput: CreateOrUpdateBackingAddressData): io.reactivex.Observable { + return io.reactivex.Observable.empty() + } } open class MockApolloClient : ApolloClientType { @@ -537,15 +542,6 @@ open class MockApolloClient : ApolloClientType { } override fun triggerThirdPartyEvent(eventInput: TPEventInputData): Observable> { - return Observable.just( -// TriggerThirdPartyEventMutation.Data( -// TriggerThirdPartyEventMutation -// .TriggerThirdPartyEvent( -// "", -// true -// ) -// ) - Pair(true, "") - ) + return Observable.just(Pair(true, "")) } } diff --git a/app/src/main/java/com/kickstarter/services/KSApolloClientV2.kt b/app/src/main/java/com/kickstarter/services/KSApolloClientV2.kt index a4fbf5fe41..40dadf203d 100644 --- a/app/src/main/java/com/kickstarter/services/KSApolloClientV2.kt +++ b/app/src/main/java/com/kickstarter/services/KSApolloClientV2.kt @@ -69,6 +69,7 @@ import com.kickstarter.services.apiresponses.updatesresponse.UpdatesGraphQlEnvel import com.kickstarter.services.mutations.CreateAttributionEventData import com.kickstarter.services.mutations.CreateBackingData import com.kickstarter.services.mutations.CreateCheckoutData +import com.kickstarter.services.mutations.CreateOrUpdateBackingAddressData import com.kickstarter.services.mutations.PostCommentData import com.kickstarter.services.mutations.SavePaymentMethodData import com.kickstarter.services.mutations.UpdateBackingData @@ -79,6 +80,7 @@ import com.kickstarter.services.transformers.complexRewardItemsTransformer import com.kickstarter.services.transformers.decodeRelayId import com.kickstarter.services.transformers.encodeRelayId import com.kickstarter.services.transformers.getCreateAttributionEventMutation +import com.kickstarter.services.transformers.getCreateOrUpdateBackingAddressMutation import com.kickstarter.services.transformers.getTriggerThirdPartyEventMutation import com.kickstarter.services.transformers.projectTransformer import com.kickstarter.services.transformers.rewardTransformer @@ -192,6 +194,7 @@ interface ApolloClientTypeV2 { ): Observable> fun createAttributionEvent(eventInput: CreateAttributionEventData): Observable + fun createOrUpdateBackingAddress(eventInput: CreateOrUpdateBackingAddressData): Observable } private const val PAGE_SIZE = 25 @@ -1630,4 +1633,32 @@ class KSApolloClientV2(val service: ApolloClient, val gson: Gson) : ApolloClient return@defer ps } } + + override fun createOrUpdateBackingAddress(eventInput: CreateOrUpdateBackingAddressData): Observable { + return Observable.defer { + val ps = PublishSubject.create() + + val mutation = getCreateOrUpdateBackingAddressMutation(eventInput) + + service.mutate(mutation) + .enqueue(object : ApolloCall.Callback() { + override fun onFailure(exception: ApolloException) { + ps.onError(exception) + } + + override fun onResponse(response: Response) { + if (response.hasErrors()) { + ps.onError(Exception(response.errors?.first()?.message ?: "")) + } + + response.data?.let { + val isSuccess = it.createOrUpdateBackingAddress()?.success() ?: false + ps.onNext(isSuccess) + } + ps.onComplete() + } + }) + return@defer ps + } + } } diff --git a/app/src/main/java/com/kickstarter/services/mutations/CreateOrUpdateBackingAddressData.kt b/app/src/main/java/com/kickstarter/services/mutations/CreateOrUpdateBackingAddressData.kt new file mode 100644 index 0000000000..ee3cce28e6 --- /dev/null +++ b/app/src/main/java/com/kickstarter/services/mutations/CreateOrUpdateBackingAddressData.kt @@ -0,0 +1,11 @@ +package com.kickstarter.services.mutations + +/*** + * CreateOrUpdateBackingAddressData is the corresponding internal data model to the GraphQL model + * [CreateOrUpdateBackingAddressInput] + */ +data class CreateOrUpdateBackingAddressData( + val backingId: String, + val addressID: String, + val clientMutationId: String? = null +) diff --git a/app/src/main/java/com/kickstarter/services/transformers/GraphQLTransformers.kt b/app/src/main/java/com/kickstarter/services/transformers/GraphQLTransformers.kt index 4fd0801c51..0b6829fa8b 100644 --- a/app/src/main/java/com/kickstarter/services/transformers/GraphQLTransformers.kt +++ b/app/src/main/java/com/kickstarter/services/transformers/GraphQLTransformers.kt @@ -1,6 +1,7 @@ package com.kickstarter.services.transformers import CreateAttributionEventMutation +import CreateOrUpdateBackingAddressMutation import TriggerThirdPartyEventMutation import UserPrivacyQuery import com.google.android.gms.common.util.Base64Utils @@ -32,6 +33,7 @@ import com.kickstarter.models.Video import com.kickstarter.models.Web import com.kickstarter.services.apiresponses.ShippingRulesEnvelope import com.kickstarter.services.mutations.CreateAttributionEventData +import com.kickstarter.services.mutations.CreateOrUpdateBackingAddressData import com.kickstarter.viewmodels.usecases.TPEventInputData import fragment.FullProject import fragment.ProjectCard @@ -40,6 +42,7 @@ import org.joda.time.DateTime import type.AppDataInput import type.CollaboratorPermission import type.CreateAttributionEventInput +import type.CreateOrUpdateBackingAddressInput import type.CreditCardPaymentType import type.CurrencyCode import type.RewardType @@ -886,3 +889,13 @@ fun getCreateAttributionEventMutation(eventInput: CreateAttributionEventData, gs return CreateAttributionEventMutation.builder().input(graphInput) .build() } + +fun getCreateOrUpdateBackingAddressMutation(eventInput: CreateOrUpdateBackingAddressData): CreateOrUpdateBackingAddressMutation { + val graphInput = + CreateOrUpdateBackingAddressInput.builder() + .addressId(eventInput.addressID) + .backingId(eventInput.backingId) + .build() + + return CreateOrUpdateBackingAddressMutation.builder().input(graphInput).build() +}