Skip to content

Commit

Permalink
refactor: reuse classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackfaded committed Jan 22, 2025
1 parent 5099c04 commit 5670c58
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ on:
jobs:
test:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.9, 3.10, 3.11, 3.12, 3.13]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install setuptools
run: ./scripts.sh setup
- name: Install dependencies
run: ./scripts.sh install
- name: Run Lint
run: ./scripts.sh lint
- name: Run Build
run: ./scripts.sh build
- name: Run Tests
run: ./scripts.sh test

sonar:
runs-on: ubuntu-22.04
needs: [test]
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ from pcp_serversdk_python import CommunicatorConfiguration, CheckoutApiClient
commerceCaseClient = CommerceCaseApiClient(communicatorConfiguration)
```

All payloads and reponses are availabe as java classes within the `com.payone.commerce.platform.lib.models.*` package. The serialization and deserialization is handled by the SDK internally. For example, to create an empty commerce case you can pass a `CreateCommerceCaseRequest` instance:
All payloads and reponses are availabe as python classes within the `pcp_serversdk_python.models` package. The serialization and deserialization is handled by the SDK internally. For example, to create an empty commerce case you can pass a `CreateCommerceCaseRequest` instance:

```python
createCommerceCaseRequest = CreateCommerceCaseRequest()
Expand Down Expand Up @@ -115,7 +115,7 @@ class App:
## Demo App

```sh
API_KEY=api_key API_SECRET=api_secret MERCHANT_ID=123 COMMERCE_CASE_ID=234 CHECKOUT_ID=345 python3 example/main.py
API_KEY=api_key API_SECRET=api_secret MERCHANT_ID=123 COMMERCE_CASE_ID=234 CHECKOUT_ID=345 ./scripts.sh run
```

**[back to top](#table-of-contents)**
Expand Down
25 changes: 14 additions & 11 deletions pcp_serversdk_python/transformer/ApplepayTransformer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from ..models import (
ApplePaymentDataTokenHeaderInformation,
ApplePaymentDataTokenInformation,
ApplePaymentTokenVersion,
ApplePayPayment,
MobilePaymentMethodSpecificInput,
Network,
PaymentProduct320SpecificInput,
)


Expand Down Expand Up @@ -32,15 +35,15 @@ def transform_apple_pay_payment_to_mobile_payment_method_specific_input(
paymentProductId=302,
publicKeyHash=header.get("publicKeyHash"),
ephemeralKey=header.get("ephemeralPublicKey"),
paymentProduct302SpecificInput={
"network": network_from_string(paymentMethod.get("network", "")),
"token": {
"version": version_from_string(paymentData.get("version", "")),
"signature": paymentData.get("signature"),
"header": {
"transactionId": header.get("transactionId"),
"applicationData": header.get("applicationData"),
},
},
},
paymentProduct302SpecificInput=PaymentProduct320SpecificInput(
network=network_from_string(paymentMethod.get("network", "")),
token=ApplePaymentDataTokenInformation(
version=version_from_string(paymentData.get("version", "")),
signature=paymentData.get("signature"),
header=ApplePaymentDataTokenHeaderInformation(
transactionId=header.get("transactionId"),
applicationData=header.get("applicationData"),
),
),
),
)
5 changes: 5 additions & 0 deletions scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ publish() {
echo "Upload complete."
}

run() {
echo "Running the package..."
python3 example/main.py
}

# Check the first argument passed to the script
case "$1" in
setup)
Expand Down
25 changes: 14 additions & 11 deletions tests/transformer/test_ApplepayTransformer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import pytest

from pcp_serversdk_python.models import (
ApplePaymentDataTokenHeaderInformation,
ApplePaymentDataTokenInformation,
ApplePaymentTokenVersion,
ApplePayPayment,
MobilePaymentMethodSpecificInput,
Network,
PaymentProduct320SpecificInput,
)
from pcp_serversdk_python.transformer.ApplepayTransformer import (
network_from_string,
Expand Down Expand Up @@ -53,17 +56,17 @@ def test_transform_apple_pay_payment_to_mobile_payment_method_specific_input():
paymentProductId=302,
publicKeyHash="publicKeyHash123",
ephemeralKey="ephemeralPublicKey123",
paymentProduct302SpecificInput={
"network": Network.VISA,
"token": {
"version": ApplePaymentTokenVersion.EC_V1,
"signature": "signature123",
"header": {
"transactionId": "transactionId123",
"applicationData": "applicationData123",
},
},
},
paymentProduct302SpecificInput=PaymentProduct320SpecificInput(
network=Network.VISA,
token=ApplePaymentDataTokenInformation(
version=ApplePaymentTokenVersion.EC_V1,
signature="signature123",
header=ApplePaymentDataTokenHeaderInformation(
transactionId="transactionId123",
applicationData="applicationData123",
),
),
),
)

result = transform_apple_pay_payment_to_mobile_payment_method_specific_input(
Expand Down

0 comments on commit 5670c58

Please sign in to comment.