Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Adjustment when setting the access token #286

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ already.
<dependency>
<groupId>com.mercadopago</groupId>
<artifactId>sdk-java</artifactId>
<version>2.1.23</version>
<version>2.1.24</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.mercadopago</groupId>
<artifactId>sdk-java</artifactId>
<version>2.1.23</version>
<version>2.1.24</version>
<packaging>jar</packaging>

<name>Mercadopago SDK</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mercadopago/MercadoPagoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/** Mercado Pago configuration class. */
public class MercadoPagoConfig {

public static final String CURRENT_VERSION = "2.1.23";
public static final String CURRENT_VERSION = "2.1.24";

public static final String PRODUCT_ID = "BC32A7VTRPP001U8NHJ0";

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/mercadopago/client/MercadoPagoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,17 @@ private Map<String, String> addDefaultHeaders(MPRequest request) {
headers.put(Headers.IDEMPOTENCY_KEY, request.createIdempotencyKey());
}

if (request!= null && !request.getUri().contains(OAUTH_TOKEN) && request.getAccessToken() != null) {
headers.put(Headers.AUTHORIZATION, String.format(BEARER, request.getAccessToken()));
if (nonNull(request) && !request.getUri().contains(OAUTH_TOKEN) && !headers.containsKey(Headers.AUTHORIZATION)) {
headers.put(Headers.AUTHORIZATION, String.format(BEARER, chooseAccessToken(request)));
}

return headers;
}

private String chooseAccessToken(MPRequest request) {
return request.getAccessToken() != null ? request.getAccessToken() : MercadoPagoConfig.getAccessToken();
}

private Map<String, String> addCustomHeaders(String uri, MPRequestOptions requestOptions) {
Map<String, String> headers = new HashMap<>();
if (nonNull(requestOptions) && nonNull(requestOptions.getCustomHeaders())) {
Expand Down
Loading