Skip to content

Commit

Permalink
feat: Add new API endpoint for canceling a payout order
Browse files Browse the repository at this point in the history
This commit adds a new API endpoint `cancelPayoutOrderById` to the `PayoutOrdersApi` class. This endpoint allows users to cancel a payout order by providing the ID of the resource. The method is a PUT request and is located at `/payout_orders/{id}/cancel`.

The commit also includes updates to the documentation, specifically in the `PayoutOrdersApi.md` file, where the new endpoint is described along with its parameters and return type.

Additionally, there are some changes made to other files such as `Makefile`, `README.md`, `EncryptedTypeAdapter.java`, `ApiKeyCreateResponse.java`, `ApiKeyRequest.java`, `ApiKeyResponse.java`, `ApiKeyResponseOnDelete.java`, `ApiKeyUpdateRequest.java`,  and 	`BalanceCommonField.java`. These changes include code refactoring, imports optimization, and minor updates to class descriptions.

These changes aim to improve code readability and maintainability.
  • Loading branch information
fcarrero committed Nov 6, 2024
1 parent 4a7228a commit 193fb27
Show file tree
Hide file tree
Showing 183 changed files with 6,981 additions and 5,190 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test:
build:
./gradlew clean build -x lintDebug
deploy:
./gradlew publish
./gradlew publish -x lintDebug
android:
rm -rf src/main/kotlin && \
rm -rf docs && \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Class | Method | HTTP request | Description
*PaymentMethodsApi* | [**deleteCustomerPaymentMethods**](docs/PaymentMethodsApi.md#deleteCustomerPaymentMethods) | **DELETE** /customers/{id}/payment_sources/{payment_method_id} | Delete Payment Method
*PaymentMethodsApi* | [**getCustomerPaymentMethods**](docs/PaymentMethodsApi.md#getCustomerPaymentMethods) | **GET** /customers/{id}/payment_sources | Get Payment Methods
*PaymentMethodsApi* | [**updateCustomerPaymentMethods**](docs/PaymentMethodsApi.md#updateCustomerPaymentMethods) | **PUT** /customers/{id}/payment_sources/{payment_method_id} | Update Payment Method
*PayoutOrdersApi* | [**cancelPayoutOrderById**](docs/PayoutOrdersApi.md#cancelPayoutOrderById) | **PUT** /payout_orders/{id}/cancel | Cancel Payout Order
*PayoutOrdersApi* | [**createPayoutOrder**](docs/PayoutOrdersApi.md#createPayoutOrder) | **POST** /payout_orders | Create payout order
*PayoutOrdersApi* | [**getPayoutOrderById**](docs/PayoutOrdersApi.md#getPayoutOrderById) | **GET** /payout_orders/{id} | Get Payout Order
*PayoutOrdersApi* | [**getPayoutOrders**](docs/PayoutOrdersApi.md#getPayoutOrders) | **GET** /payout_orders | Get a list of Payout Orders
Expand Down
49 changes: 49 additions & 0 deletions docs/PayoutOrdersApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,61 @@ All URIs are relative to *https://api.conekta.io*

Method | HTTP request | Description
------------- | ------------- | -------------
[**cancelPayoutOrderById**](PayoutOrdersApi.md#cancelPayoutOrderById) | **PUT** /payout_orders/{id}/cancel | Cancel Payout Order
[**createPayoutOrder**](PayoutOrdersApi.md#createPayoutOrder) | **POST** /payout_orders | Create payout order
[**getPayoutOrderById**](PayoutOrdersApi.md#getPayoutOrderById) | **GET** /payout_orders/{id} | Get Payout Order
[**getPayoutOrders**](PayoutOrdersApi.md#getPayoutOrders) | **GET** /payout_orders | Get a list of Payout Orders



## cancelPayoutOrderById

> PayoutOrderResponse cancelPayoutOrderById(id, acceptLanguage)
Cancel Payout Order

Cancel a payout Order resource that corresponds to a payout order ID.

### Example

```java
// Import classes:
//import io.conekta.PayoutOrdersApi;

PayoutOrdersApi apiInstance = new PayoutOrdersApi();
String id = 6307a60c41de27127515a575; // String | Identifier of the resource
String acceptLanguage = es; // String | Use for knowing which language to use
try {
PayoutOrderResponse result = apiInstance.cancelPayoutOrderById(id, acceptLanguage);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PayoutOrdersApi#cancelPayoutOrderById");
e.printStackTrace();
}
```

### Parameters


Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**id** | **String**| Identifier of the resource | [default to null]
**acceptLanguage** | **String**| Use for knowing which language to use | [optional] [default to es] [enum: es, en]

### Return type

[**PayoutOrderResponse**](PayoutOrderResponse.md)

### Authorization

[bearerAuth](../README.md#bearerAuth)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/vnd.conekta-v2.1.0+json


## createPayoutOrder

> PayoutOrderResponse createPayoutOrder(payoutOrder, acceptLanguage)
Expand Down
53 changes: 16 additions & 37 deletions src/main/java/io/conekta/EncryptedTypeAdapter.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,34 @@
package io.conekta;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import javax.crypto.Cipher;
import java.io.IOException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.Security;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.encoders.Base64;

public class EncryptedTypeAdapter extends TypeAdapter<String> {
public class EncryptedTypeAdapter {

private static final String PUBLIC_KEY_PEM = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjet2Jm4iPJTqDlW64tEG\nI9/dJTJAcn3OQdHrEwNXCz0/Rewqcv/Hm+V0klsUiS9h2W5CLC42q6wGhtl9Buu5\nvefuLVyxc8klEEjrSz/5AgfZ4HvzatbVX0KQhHI1j+caOjatDHM/ih13Rj7HIJFn\nAcutRB9vyFiCVluqRhlB9/64sqGtVmxJAir7WJp4TmpPvSEqeGKQIb80Tq+FYY7f\ntpMxQpsBT8B6y4Kn95ZfDH72H3yJezs/mExVB3M/OCBg+xt/c3dXp65JsbS482c4\nKhkxxHChNn1Y/nZ8kFYzakRGhh0BMqkvkqtAwcQJK1xPx2jRELS1vj7OFfMR+3ms\nSQIDAQAB\n-----END PUBLIC KEY-----";

private PublicKey publicKey;
private PublicKey loadPublicKey(String publicKeyPem) throws NoSuchAlgorithmException, InvalidKeySpecException {
byte[] keyBytes = Base64.decode(publicKeyPem.replaceAll("-----BEGIN PUBLIC KEY-----", "")
.replaceAll("-----END PUBLIC KEY-----", "").replaceAll("\\s+", ""));
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
return KeyFactory.getInstance("RSA").generatePublic(spec);

public EncryptedTypeAdapter() throws Exception {
Security.addProvider(new BouncyCastleProvider());
this.publicKey = loadPublicKey(PUBLIC_KEY_PEM);
}

@Override
public void write(JsonWriter out, String value) throws IOException {
public String encryptValue(String plainText) {
try {
out.value(encrypt(value, publicKey));
} catch (Exception e) {
throw new IOException("Error encrypting value", e);
PublicKey publicKey = loadPublicKey(PUBLIC_KEY_PEM);
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");

Check failure

Code scanning / CodeQL

Use of RSA algorithm without OAEP High

This specification is used to
initialize an RSA cipher
without OAEP padding.
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] encryptedBytes = cipher.doFinal(plainText.getBytes("UTF-8"));
return Base64.toBase64String(encryptedBytes);
}catch (Exception e){
return plainText;
}
}

@Override
public String read(JsonReader in) throws IOException {
return in.nextString();
}

public static String encrypt(String plainText, PublicKey publicKey) throws Exception {
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] encryptedBytes = cipher.doFinal(plainText.getBytes("UTF-8"));
return Base64.toBase64String(encryptedBytes);
}

private PublicKey loadPublicKey(String publicKeyPem) throws Exception {
byte[] keyBytes = Base64.decode(publicKeyPem.replaceAll("-----BEGIN PUBLIC KEY-----", "")
.replaceAll("-----END PUBLIC KEY-----", "").replaceAll("\\s+", ""));
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
return KeyFactory.getInstance("RSA").generatePublic(spec);
}
}
56 changes: 56 additions & 0 deletions src/main/java/io/conekta/PayoutOrdersApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,62 @@ public String GetApiKey(){
return this.apiKey;
}

/**
* Cancel Payout Order
* Cancel a payout Order resource that corresponds to a payout order ID.
* @param id Identifier of the resource
* @param acceptLanguage Use for knowing which language to use
* @return PayoutOrderResponse
*/
public PayoutOrderResponse cancelPayoutOrderById (String id, String acceptLanguage) throws ApiException {
Object localVarPostBody = null;
// verify the required parameter 'id' is set
if (id == null) {
throw new ApiException(400, "Missing the required parameter 'id' when calling cancelPayoutOrderById");
}

// create path and map variables
String localVarPath = "/payout_orders/{id}/cancel".replaceAll("\\{format\\}","json").replaceAll("\\{" + "id" + "\\}", apiInvoker.escapeString(id.toString()));

// query params
List<Pair> localVarQueryParams = new ArrayList<Pair>();
// header params
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
// form params
Map<String, String> localVarFormParams = new HashMap<String, String>();

localVarHeaderParams.put("Accept-Language", ApiInvoker.parameterToString(acceptLanguage));

localVarHeaderParams.put("Authorization", ApiInvoker.parameterToString("Bearer " + apiKey));
localVarHeaderParams.put("Conekta-Client-User-Agent", "{\"agent\": \"Conekta Android SDK\"}");

String[] localVarContentTypes = {

};
String localVarContentType = localVarContentTypes.length > 0 ? localVarContentTypes[0] : "application/json";

if (localVarContentType.startsWith("multipart/form-data")) {
// file uploading
MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create();


localVarPostBody = localVarBuilder.build();
} else {
// normal form params
}

try {
String localVarResponse = apiInvoker.invokeAPI(basePath, localVarPath, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarContentType);
if(localVarResponse != null){
return (PayoutOrderResponse) ApiInvoker.deserialize(localVarResponse, "", PayoutOrderResponse.class);
}
else {
return null;
}
} catch (ApiException ex) {
throw ex;
}
}
/**
* Create payout order
* Create a new payout order.
Expand Down
Loading

0 comments on commit 193fb27

Please sign in to comment.