Add Registrar client ID to Braintree payment info

The client ID is passed as the "customer ID" to Braintree. In order for
this to work, someone needs to go into the Braintree website beforehand,
click on "New Customer" link, and create the customer record with a
matching ID.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=116769955
This commit is contained in:
jart 2016-03-09 09:09:46 -08:00 committed by Ben McIlwain
parent dd633c9e72
commit 3eef39126d
5 changed files with 52 additions and 0 deletions

View file

@ -28,6 +28,7 @@ import com.google.domain.registry.request.RequestModule;
import com.google.domain.registry.request.RequestScope;
import com.google.domain.registry.ui.server.registrar.RegistrarPaymentAction;
import com.google.domain.registry.ui.server.registrar.RegistrarPaymentSetupAction;
import com.google.domain.registry.ui.server.registrar.RegistrarUserModule;
import com.google.domain.registry.whois.WhoisHttpServer;
import com.google.domain.registry.whois.WhoisModule;
import com.google.domain.registry.whois.WhoisServer;
@ -39,6 +40,7 @@ import dagger.Subcomponent;
@Subcomponent(
modules = {
RdapModule.class,
RegistrarUserModule.class,
RequestModule.class,
WhoisModule.class,
})

View file

@ -24,6 +24,7 @@ import static java.util.Arrays.asList;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.domain.registry.config.ConfigModule.Config;
import com.google.domain.registry.model.registrar.Registrar;
import com.google.domain.registry.request.Action;
import com.google.domain.registry.request.JsonActionRunner;
import com.google.domain.registry.request.JsonActionRunner.JsonAction;
@ -145,6 +146,7 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
@Inject BraintreeGateway braintreeGateway;
@Inject JsonActionRunner jsonActionRunner;
@Inject Registrar registrar;
@Inject @Config("braintreeMerchantAccountIds") ImmutableMap<CurrencyUnit, String> accountIds;
@Inject RegistrarPaymentAction() {}
@ -183,6 +185,7 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
.amount(amount.getAmount())
.paymentMethodNonce(paymentMethodNonce)
.merchantAccountId(merchantAccountId)
.customerId(registrar.getClientIdentifier())
.options()
.submitForSettlement(true)
.done());

View file

@ -0,0 +1,36 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.domain.registry.ui.server.registrar;
import com.google.domain.registry.model.registrar.Registrar;
import com.google.domain.registry.request.HttpException.ForbiddenException;
import dagger.Module;
import dagger.Provides;
import javax.servlet.http.HttpServletRequest;
/** Registrar Console module providing reference to logged-in {@link Registrar}. */
@Module
public final class RegistrarUserModule {
@Provides
static Registrar provideRegistrarUser(SessionUtils sessionUtils, HttpServletRequest req) {
if (!sessionUtils.checkRegistrarConsoleLogin(req)) {
throw new ForbiddenException("Not authorized to access Registrar Console");
}
return Registrar.loadByClientId(sessionUtils.getRegistrarClientId(req));
}
}

View file

@ -33,6 +33,7 @@ import com.google.domain.registry.util.FormattingLogger;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@ -47,6 +48,7 @@ public class SessionUtils {
private final UserService userService;
@Inject
public SessionUtils(UserService userService) {
this.userService = checkNotNull(userService);
}

View file

@ -22,6 +22,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableMap;
import com.google.domain.registry.model.registrar.Registrar;
import com.google.domain.registry.testing.AppEngineRule;
import com.braintreegateway.BraintreeGateway;
import com.braintreegateway.Result;
@ -35,6 +37,7 @@ import com.braintreegateway.ValidationErrors;
import org.joda.money.CurrencyUnit;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@ -49,6 +52,9 @@ import java.math.BigDecimal;
@RunWith(MockitoJUnitRunner.class)
public class RegistrarPaymentActionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Mock
private BraintreeGateway braintreeGateway;
@ -71,6 +77,7 @@ public class RegistrarPaymentActionTest {
@Before
public void before() throws Exception {
paymentAction.registrar = Registrar.loadByClientId("TheRegistrar");
paymentAction.accountIds =
ImmutableMap.of(
CurrencyUnit.USD, "merchant-account-usd",
@ -106,6 +113,8 @@ public class RegistrarPaymentActionTest {
.isEqualTo(BigDecimal.valueOf(123.4).setScale(2));
assertThat(extractField(String.class, transactionRequest, "merchantAccountId"))
.isEqualTo("merchant-account-usd");
assertThat(extractField(String.class, transactionRequest, "customerId"))
.isEqualTo("TheRegistrar");
}
@Test