本文整理匯總了Java中com.braintreegateway.CustomerRequest類的典型用法代碼示例。如果您正苦於以下問題:Java CustomerRequest類的具體用法?Java CustomerRequest怎麽用?Java CustomerRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CustomerRequest類屬於com.braintreegateway包,在下文中一共展示了CustomerRequest類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createRequest
import com.braintreegateway.CustomerRequest; //導入依賴的package包/類
private CustomerRequest createRequest(Registrar registrar) {
CustomerRequest result =
new CustomerRequest()
.id(registrar.getClientId())
.customerId(registrar.getClientId())
.company(registrar.getRegistrarName());
Optional<RegistrarContact> contact = getBillingContact(registrar);
if (contact.isPresent()) {
result.email(contact.get().getEmailAddress());
result.phone(contact.get().getPhoneNumber());
result.fax(contact.get().getFaxNumber());
} else {
result.email(registrar.getEmailAddress());
result.phone(registrar.getPhoneNumber());
result.fax(registrar.getFaxNumber());
}
return result;
}
示例2: testUpdateUnknownCustomer
import com.braintreegateway.CustomerRequest; //導入依賴的package包/類
@Test
public void testUpdateUnknownCustomer() throws Exception {
try {
String id = "unknown-" + UUID.randomUUID().toString();
HashMap<String, Object> headers = new HashMap<>();
headers.put("CamelBraintree.id", id);
requestBodyAndHeaders("direct://UPDATE_IN_BODY",
new CustomerRequest().firstName(id),
headers);
fail("Should have thrown NotFoundException");
} catch (CamelExecutionException e) {
assertIsInstanceOf(NotFoundException.class, e.getCause().getCause());
}
}
示例3: sync
import com.braintreegateway.CustomerRequest; //導入依賴的package包/類
/**
* Syncs {@code registrar} with Braintree customer entry, creating it if one doesn't exist.
*
* <p>The customer ID will be the same as {@link Registrar#getClientId()}.
*
* <p>Creating a customer object in Braintree's database is a necessary step in order to associate
* a payment with a registrar. The transaction will fail if the customer object doesn't exist.
*
* @throws IllegalArgumentException if {@code registrar} is not using BRAINTREE billing
* @throws VerifyException if the Braintree API returned a failure response
*/
public void sync(Registrar registrar) {
String id = registrar.getClientId();
checkArgument(registrar.getBillingMethod() == Registrar.BillingMethod.BRAINTREE,
"Registrar (%s) billing method (%s) is not BRAINTREE", id, registrar.getBillingMethod());
CustomerRequest request = createRequest(registrar);
Result<Customer> result;
if (doesCustomerExist(id)) {
result = braintree.customer().update(id, request);
} else {
result = braintree.customer().create(request);
}
verify(result.isSuccess(),
"Failed to sync registrar (%s) to braintree customer: %s", id, result.getMessage());
}
示例4: doPostSetup
import com.braintreegateway.CustomerRequest; //導入依賴的package包/類
@Override
protected void doPostSetup() throws Exception {
this.gateway = getGateway();
this.customer = gateway.customer().create(
new CustomerRequest()
.firstName("user")
.lastName(UUID.randomUUID().toString())
).getTarget();
if (customer != null) {
LOG.info("Customer created - id={}", this.customer.getId());
}
}
示例5: doPostSetup
import com.braintreegateway.CustomerRequest; //導入依賴的package包/類
@Override
protected void doPostSetup() throws Exception {
this.gateway = getGateway();
this.customer = gateway.customer().create(
new CustomerRequest()
.firstName("user")
.lastName(UUID.randomUUID().toString())
).getTarget();
if (customer != null) {
LOG.info("Customer created - id={}", this.customer.getId());
}
}
示例6: testWrongCustomerCreateRequest
import com.braintreegateway.CustomerRequest; //導入依賴的package包/類
@Test
public void testWrongCustomerCreateRequest() throws Exception {
// Create customer
Result<Customer> createResult = requestBody(
"direct://CREATE_IN_BODY",
new CustomerRequest()
.firstName("user")
.lastName(UUID.randomUUID().toString())
.company("Apache")
.email("wrongEmail")
.website("http://user.braintree.camel"),
Result.class
);
assertNotNull(createResult);
assertFalse(createResult.isSuccess());
final ValidationErrors errors = createResult.getErrors();
assertNotNull(errors);
assertNotNull(errors.getAllDeepValidationErrors());
ValidationError invalidMailError = null;
for (ValidationError error : errors.getAllDeepValidationErrors()) {
if (error.getCode() == ValidationErrorCode.CUSTOMER_EMAIL_FORMAT_IS_INVALID) {
invalidMailError = error;
break;
}
}
assertNotNull(invalidMailError);
}
示例7: testCustomerManagementWorkflow
import com.braintreegateway.CustomerRequest; //導入依賴的package包/類
/**
* Customers management workflow:
* - create a customer
* - lookup by id
* - update first name
* - delete by id
* - confirm deletion by searching again
*
* @throws Exception
*/
@Test
public void testCustomerManagementWorkflow() throws Exception {
String customerLastName = UUID.randomUUID().toString();
String customerId = null;
// Create customer
Result<Customer> createResult = requestBody(
"direct://CREATE_IN_BODY",
new CustomerRequest()
.firstName("user")
.lastName(customerLastName)
.company("Apache")
.email("[email protected]")
.website("http://user.braintree.camel"),
Result.class
);
assertNotNull(createResult);
assertTrue(createResult.isSuccess());
assertNotNull(createResult.getTarget());
assertNotNull(createResult.getTarget().getId());
customerId = createResult.getTarget().getId();
// Find customer by ID
Customer customer1 = requestBody("direct://FIND_IN_BODY", customerId, Customer.class);
assertNotNull(customer1);
assertEquals("user", customer1.getFirstName());
assertEquals(customerLastName, customer1.getLastName());
assertEquals("Apache", customer1.getCompany());
assertEquals("[email protected]", customer1.getEmail());
assertEquals("http://user.braintree.camel", customer1.getWebsite());
// Update customer
HashMap<String, Object> headers = new HashMap<>();
headers.put("CamelBraintree.id", customerId);
Result<Customer> updateResult = requestBodyAndHeaders(
"direct://UPDATE_IN_BODY",
new CustomerRequest().firstName("user-mod"),
headers,
Result.class
);
assertNotNull(updateResult);
assertTrue(updateResult.isSuccess());
assertNotNull(updateResult.getTarget());
assertEquals("user-mod", updateResult.getTarget().getFirstName());
// Delete customer
Result<Customer> customerResult = requestBody("direct://DELETE_IN_BODY", customerId, Result.class);
assertNotNull(customerResult);
assertTrue(customerResult.isSuccess());
assertNull(customerResult.getTarget());
// Check if customer has been deleted customer
ResourceCollection<Customer> customers = requestBody(
"direct://SEARCH_IN_BODY",
new CustomerSearchRequest().id().is(customerId),
ResourceCollection.class
);
assertNotNull(customers);
assertEquals(0, customers.getMaximumSize());
}