-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from EduardoSorokin/authorization-suggestion-t…
…o-register Authorization Request with Registration Suggestion
- Loading branch information
Showing
43 changed files
with
3,228 additions
and
737 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...i/application/authorization/register/CreateAuthorizationWithCompanyAccountSuggestion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package br.com.uol.pagseguro.example.api.application.authorization.register; | ||
|
||
import br.com.uol.pagseguro.api.PagSeguro; | ||
import br.com.uol.pagseguro.api.PagSeguroEnv; | ||
import br.com.uol.pagseguro.api.application.authorization.AuthorizationRegistration; | ||
import br.com.uol.pagseguro.api.application.authorization.AuthorizationRegistrationBuilder; | ||
import br.com.uol.pagseguro.api.application.authorization.RegisteredAuthorization; | ||
import br.com.uol.pagseguro.api.common.domain.PermissionCode; | ||
import br.com.uol.pagseguro.api.common.domain.builder.*; | ||
import br.com.uol.pagseguro.api.common.domain.enums.AccountType; | ||
import br.com.uol.pagseguro.api.common.domain.enums.DocumentType; | ||
import br.com.uol.pagseguro.api.common.domain.enums.PhoneType; | ||
import br.com.uol.pagseguro.api.credential.Credential; | ||
|
||
public class CreateAuthorizationWithCompanyAccountSuggestion { | ||
|
||
public static void main(String[] args) { | ||
|
||
String appId = "your_app_id"; | ||
String appKey = "your_app_key"; | ||
|
||
try{ | ||
final PagSeguro pagSeguro = PagSeguro.instance(Credential.applicationCredential(appId, | ||
appKey), PagSeguroEnv.SANDBOX); | ||
|
||
// Registra as autorizações com sugestão de cadastro de empresa | ||
AuthorizationRegistration authorizationRegistration = | ||
new AuthorizationRegistrationBuilder() | ||
.withReference("123") | ||
.addPermission(PermissionCode.Code.CREATE_CHECKOUTS) | ||
.withRedirectURL("http://seusite.com.br/redirect") | ||
.withNotificationUrl("http://seusite.com.br/notification") | ||
.withAccount(new AccountRegisterSuggestionBuilder() | ||
.withEmail("[email protected]") | ||
.withType(AccountType.COMPANY) | ||
.withCompany(new CompanyBuilder() | ||
.withName("Seu Site") | ||
.addDocument(new DocumentBuilder() | ||
.withType(DocumentType.CNPJ) | ||
.withValue("17302417000101") | ||
) | ||
.withDisplayName("Seu Site") | ||
.withWebsiteUrl("http://www.seusite.com.br") | ||
.withPartner(new PartnerBuilder() | ||
.withName("Antonio Carlos") | ||
.addDocument(new DocumentBuilder() | ||
.withType(DocumentType.CPF) | ||
.withValue("34163749160") | ||
) | ||
.withBirthDate("1982-02-05") | ||
) | ||
.addPhone(new PhoneAccountBuilder() | ||
.withType(PhoneType.BUSINESS) | ||
.withAreaCode("11") | ||
.withNumber("30302323") | ||
) | ||
.addPhone(new PhoneAccountBuilder() | ||
.withType(PhoneType.BUSINESS) | ||
.withAreaCode("11") | ||
.withNumber("976302323") | ||
) | ||
.withAddress(new AddressBuilder() | ||
.withPostalCode("01452002") | ||
.withStreet("Av. Brig. Faria Lima") | ||
.withNumber("1384") | ||
.withComplement("5o andar") | ||
.withDistrict("Jardim Paulistano") | ||
.withCity("Sao Paulo") | ||
.withState("SP") | ||
.withCountry("BRA") | ||
) | ||
) | ||
) | ||
.build(); | ||
|
||
RegisteredAuthorization ra = pagSeguro.authorizations().registerWithSuggestion(authorizationRegistration); | ||
System.out.print(ra); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...pi/application/authorization/register/CreateAuthorizationWithPersonAccountSuggestion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package br.com.uol.pagseguro.example.api.application.authorization.register; | ||
|
||
import br.com.uol.pagseguro.api.PagSeguro; | ||
import br.com.uol.pagseguro.api.PagSeguroEnv; | ||
import br.com.uol.pagseguro.api.application.authorization.AuthorizationRegistration; | ||
import br.com.uol.pagseguro.api.application.authorization.AuthorizationRegistrationBuilder; | ||
import br.com.uol.pagseguro.api.application.authorization.RegisteredAuthorization; | ||
import br.com.uol.pagseguro.api.common.domain.PermissionCode; | ||
import br.com.uol.pagseguro.api.common.domain.builder.*; | ||
import br.com.uol.pagseguro.api.common.domain.enums.AccountType; | ||
import br.com.uol.pagseguro.api.common.domain.enums.DocumentType; | ||
import br.com.uol.pagseguro.api.common.domain.enums.PhoneType; | ||
import br.com.uol.pagseguro.api.credential.Credential; | ||
|
||
public class CreateAuthorizationWithPersonAccountSuggestion { | ||
|
||
public static void main(String[] args) { | ||
|
||
String appId = "your_app_id"; | ||
String appKey = "your_app_key"; | ||
|
||
try{ | ||
final PagSeguro pagSeguro = PagSeguro.instance(Credential.applicationCredential(appId, | ||
appKey), PagSeguroEnv.SANDBOX); | ||
|
||
// Registra as autorizações com sugestão de cadastro de pessoa | ||
AuthorizationRegistration authorizationRegistration = | ||
new AuthorizationRegistrationBuilder() | ||
.withReference("123") | ||
.addPermission(PermissionCode.Code.CREATE_CHECKOUTS) | ||
.addPermission(PermissionCode.Code.SEARCH_TRANSACTIONS) | ||
.addPermission(PermissionCode.Code.RECEIVE_TRANSACTION_NOTIFICATIONS) | ||
.withRedirectURL("http://seusite.com.br/redirect") | ||
.withNotificationUrl("http://seusite.com.br/notification") | ||
.withAccount(new AccountRegisterSuggestionBuilder() | ||
.withEmail("[email protected]") | ||
.withType(AccountType.SELLER) | ||
.withPerson(new PersonBuilder() | ||
.withName("Antonio Carlos") | ||
.addDocument(new DocumentBuilder() | ||
.withType(DocumentType.CPF) | ||
.withValue("23606838450") | ||
) | ||
.withBirthDate("1982-02-05") | ||
.addPhone(new PhoneAccountBuilder() | ||
.withType(PhoneType.HOME) | ||
.withAreaCode("11") | ||
.withNumber("30302323") | ||
) | ||
.addPhone(new PhoneAccountBuilder() | ||
.withType(PhoneType.MOBILE) | ||
.withAreaCode("11") | ||
.withNumber("976302323") | ||
) | ||
.withAddress(new AddressBuilder() | ||
.withPostalCode("01452002") | ||
.withStreet("Av. Brig. Faria Lima") | ||
.withNumber("1384") | ||
.withComplement("5o andar") | ||
.withDistrict("Jardim Paulistano") | ||
.withCity("Sao Paulo") | ||
.withState("SP") | ||
.withCountry("BRA") | ||
) | ||
) | ||
) | ||
.build(); | ||
|
||
RegisteredAuthorization ra = pagSeguro.authorizations().registerWithSuggestion(authorizationRegistration); | ||
System.out.print(ra); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...c/main/java/br/com/uol/pagseguro/api/application/authorization/AccountV2XMLConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package br.com.uol.pagseguro.api.application.authorization; | ||
|
||
import br.com.uol.pagseguro.api.common.domain.AccountRegisterSuggestion; | ||
|
||
import javax.xml.bind.annotation.XmlType; | ||
|
||
@XmlType(propOrder = { "email", "type", "person", "company" }) | ||
public class AccountV2XMLConverter { | ||
|
||
private final static PersonV2XMLConverter PERSON_V_2_XML_CONVERTER = new PersonV2XMLConverter(); | ||
private final static CompanyV2XMLConverter COMPANY_V_2_XML_CONVERTER = new CompanyV2XMLConverter(); | ||
|
||
private String email; | ||
private String type; | ||
private PersonV2XMLConverter person; | ||
private CompanyV2XMLConverter company; | ||
|
||
public AccountV2XMLConverter() { | ||
} | ||
|
||
public AccountV2XMLConverter(String email, String type, PersonV2XMLConverter person, CompanyV2XMLConverter company) { | ||
this.email = email; | ||
this.type = type; | ||
this.person = person; | ||
this.company = company; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public PersonV2XMLConverter getPerson() { | ||
return person; | ||
} | ||
|
||
public void setPerson(PersonV2XMLConverter person) { | ||
this.person = person; | ||
} | ||
|
||
public CompanyV2XMLConverter getCompany() { | ||
return company; | ||
} | ||
|
||
public void setCompany(CompanyV2XMLConverter company) { | ||
this.company = company; | ||
} | ||
|
||
/** | ||
* Convert attributes in request XML | ||
* | ||
* @param account Account register suggestion data | ||
* @see AccountRegisterSuggestion | ||
* @return AccountV2XMLConverter | ||
*/ | ||
public AccountV2XMLConverter convert(AccountRegisterSuggestion account) { | ||
if (account == null) { | ||
return null; | ||
} | ||
|
||
AccountV2XMLConverter convertedAccount = new AccountV2XMLConverter(); | ||
convertedAccount.setEmail(account.getEmail()); | ||
convertedAccount.setType(account.getType()); | ||
convertedAccount.setPerson(PERSON_V_2_XML_CONVERTER.convert(account.getPerson())); | ||
convertedAccount.setCompany(COMPANY_V_2_XML_CONVERTER.convert(account.getCompany())); | ||
return convertedAccount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.