Skip to content

Commit

Permalink
Merge pull request #286 from mercadopago/fix/adjustment-setting-acces…
Browse files Browse the repository at this point in the history
…s-token

[Fix] Adjustment when setting the access token
  • Loading branch information
renanneri01 authored May 21, 2024
2 parents 4facb9f + 712fd59 commit 70c2f21
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
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

0 comments on commit 70c2f21

Please sign in to comment.