Sync registrar to Braintree customer record automatically

In order to set the customerId field on a payment, the customer entry
must exist in Braintree's database. This CL causes it to be created or
updated before processing the payment.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=118530040
This commit is contained in:
jart 2016-03-29 18:37:33 -07:00 committed by Justine Tunney
parent b3125ae070
commit dcbabd06a6
8 changed files with 162 additions and 12 deletions

View file

@ -14,6 +14,7 @@ java_library(
"//java/com/google/common/collect",
"//java/com/google/common/io",
"//java/com/google/common/net",
"//java/com/google/domain/registry/braintree",
"//java/com/google/domain/registry/config",
"//java/com/google/domain/registry/export/sheet",
"//java/com/google/domain/registry/flows",

View file

@ -21,6 +21,7 @@ import static java.util.Arrays.asList;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
import com.google.domain.registry.braintree.BraintreeRegistrarSyncer;
import com.google.domain.registry.config.ConfigModule.Config;
import com.google.domain.registry.config.RegistryEnvironment;
import com.google.domain.registry.model.registrar.Registrar;
@ -76,6 +77,7 @@ import javax.inject.Inject;
public final class RegistrarPaymentSetupAction implements Runnable, JsonAction {
@Inject BraintreeGateway braintreeGateway;
@Inject BraintreeRegistrarSyncer customerSyncer;
@Inject JsonActionRunner jsonActionRunner;
@Inject Registrar registrar;
@Inject RegistryEnvironment environment;
@ -93,6 +95,7 @@ public final class RegistrarPaymentSetupAction implements Runnable, JsonAction {
if (!json.isEmpty()) {
return JsonResponseHelper.create(ERROR, "JSON request object must be empty");
}
// payment.js is hard-coded to display a specific SOY error template when encountering the
// following error messages.
if (environment == RegistryEnvironment.SANDBOX) {
@ -102,6 +105,10 @@ public final class RegistrarPaymentSetupAction implements Runnable, JsonAction {
// Registrar needs to contact support to have their billing bit flipped.
return JsonResponseHelper.create(ERROR, "not-using-cc-billing");
}
// In order to set the customerId field on the payment, the customer must exist.
customerSyncer.sync(registrar);
return JsonResponseHelper
.create(SUCCESS, "Success", asList(
ImmutableMap.of(