Skip to main content

No project description provided

Project description

PAYONE Commerce Platform Python SDK

Quality Gate Status Coverage PyPI - Version PyPI - Downloads

Welcome to the Python SDK for the PAYONE Commerce Platform! This repository contains a powerful, easy-to-use software development kit (SDK) designed to simplify the integration of online payment processing into your applications.

Table of Contents

Features

  • Easy Integration: Seamlessly integrate online payment processing into your application.
  • Secure Transactions: Built with security best practices to ensure safe transactions.
  • Extensive Documentation: Detailed documentation to help you get started quickly.
  • Open Source: Fully open source and community-driven.

Installation

python3 -m pip install "pcp_serversdk_python"

back to top

Usage

General

To use this SDK you need to construct a CommunicatorConfiguration which encapsulate everything needed to connect to the PAYONE Commerce Platform.

from pcp_serversdk_python import CommunicatorConfiguration

API_KEY = os.environ['API_KEY']
API_SECRET = os.environ['API_SECRET']

communicatorConfiguration = CommunicatorConfiguration(API_KEY, API_SECRET, "https://api.preprod.commerce.payone.com")

With the configuration you can create an API client for each reource you want to interact with. For example to create a commerce case you can use the CommerceCaseApiClient.

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:

createCommerceCaseRequest = CreateCommerceCaseRequest()
createCommerceCaseResponse = commerceCaseClient.createCommerceCaseRequest('merchant_id', createCommerceCaseRequest);

The models directly map to the API as described in PAYONE Commerce Platform API Reference. For an in depth example you can take a look at the demo app.

Error Handling

When making a request any client may throw a ApiException. There two subtypes of this exception:

  • ApiErrorReponseException: This exception is thrown when the API returns an well-formed error response. The given errors are deserialized into APIError objects which are availble via the getErrors() method on the exception. They usually contain useful information about what is wrong in your request or the state of the resource.
  • ApiResponseRetrievalException: This exception is a catch-all exception for any error that cannot be turned into a helpful error response. This includes malformed responses or unknown responses.

Network errors are not wrap, you can should handle the standard IOExeption.

Client Side

For most payment methods some information from the client is needed, e.g. payment information given by Apple when a payment via ApplePay suceeds. PAYONE provides client side SDKs which helps you interact the third party payment providers. You can find the SDKs under the PAYONE GitHub organization. Either way ensure to never store or even send credit card information to your server. The PAYONE Commerce Platform never needs access to the credit card information. The client side is responsible for safely retrieving a credit card token. This token must be used with this SDK.

Apple Pay

When a client is successfully made a payment via ApplePay it receives a ApplePayPayment. This structure is accessible as the ApplePayPayment class. You can use the ApplePayTransformer to map an ApplePayPayment to a MobilePaymentMethodSpecificInput which can be used for payment executions or order requests. The transformer has a static method transformApplePayPaymentToMobilePaymentMethodSpecificInput() which takes an ApplePayPayment and returns a MobilePaymentMethodSpecificInput. The transformer does not check if the response is complete, if anything is missing the field will be set to null.

from pcp_serversdk_python.models import ApplePayPayment, MobilePaymentMethodSpecificInput
from pcp_serversdk_python.transformer.ApplepayTransformer import transform_apple_pay_payment_to_mobile_payment_method_specific_input
import json

class App:
    def get_json_string_from_request_somehow(self):
        # Communicate with the client...
        message = ""
        return message

    def prepare_payment_for_apple_pay_payment(self):
        payment_json = self.get_json_string_from_request_somehow()
        payment = ApplePayPayment(**json.loads(payment_json))
        input = transform_apple_pay_payment_to_mobile_payment_method_specific_input(payment)
        # Wrap the input into a larger request and send to the PCP API
        # ...
    ...

back to top

Demo App

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

back to top

Contributing

See Contributing

back to top

Releasing the library

Preparing the Release

  • Checkout develop branch
  • Create release branch (release/0.1.0)
git checkout -b release/0.1.0
  • Run prepare-release.sh script to set correct version
./prepare-release.sh

Changelog Generation with Conventional Changelog

After calling the prepare_release.sh script, it is recommended to manually trigger the changelog generation script (which uses conventional-changelog).

  1. Conventional Commit Messages:

    • Ensure all commit messages follow the conventional commit format, which helps in automatic changelog generation.
    • Commit messages should be in the format: type(scope): subject.
  2. Enforcing Commit Messages:

    • We enforce conventional commit messages using Lefthook with commitlint.
    • This setup ensures that all commit messages are validated before they are committed.
  3. Generate Changelog:

    • Run the changelog generation script to update the CHANGELOG.md file:
      npm run changelog
      
    • Review and commit the updated changelog before proceeding with the release.

Merging the Release Branch

  • Create PR on develop branch
  • Merge develop in main branch

GitHub Action for Release

After successfully merging all changes to the main branch, an admin can trigger a GitHub Action to finalize and publish the release. This action ensures that the release process is automated, consistent, and deploys the new release from the main branch.

Triggering the GitHub Action:

  • Only admins can trigger the release action.
  • Ensure that all changes are committed to the main branch.
  • Navigate to the Actions tab on your GitHub repository and manually trigger the release action for the main branch.

Optional: Creating a GitHub Release

Once the release has been published to PyPi, developers can start using the latest version of the SDK. However, if you want to make the release more visible and include detailed release notes, you can optionally create a GitHub release.

  1. Navigate to the Releases Page: Go to the "Releases" section of your repository on GitHub.
  2. Draft a New Release: Click "Draft a new release".
  3. Tag the Release: Select the version tag that corresponds to the version you just published on npm (e.g., v0.1.0).
  4. Release Title: Add a descriptive title for the release (e.g., v0.1.0 - Initial Release).
  5. Auto-Generated Release Notes: GitHub can automatically generate release notes based on merged pull requests and commit history. You can review these notes, adjust the content, and highlight important changes.
  6. Publish the Release: Once you're satisfied with the release notes, click "Publish release".

Creating a GitHub release is optional, but it can provide additional context and visibility for your users. For detailed guidance, refer to the GitHub documentation on managing releases.

back to top

License

This project is licensed under the MIT License - see the LICENSE file for details.


Thank you for using our SDK for Online Payments! If you have any questions or need further assistance, feel free to open an issue or contact us.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pcp_serversdk_python-1.0.0.tar.gz (39.7 kB view details)

Uploaded Source

Built Distribution

pcp_serversdk_python-1.0.0-py3-none-any.whl (91.1 kB view details)

Uploaded Python 3

File details

Details for the file pcp_serversdk_python-1.0.0.tar.gz.

File metadata

  • Download URL: pcp_serversdk_python-1.0.0.tar.gz
  • Upload date:
  • Size: 39.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pcp_serversdk_python-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e19ecfe1bd99d4fc7331ea4167521e250cb44729550daeb0f5ce3f08bdce118c
MD5 c4af2468b7af54bc4b03005b401ceb91
BLAKE2b-256 2d6c2c8cf9303085c44400d16a3af82200118b0d787d13ddb7c56985b7f767bb

See more details on using hashes here.

File details

Details for the file pcp_serversdk_python-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pcp_serversdk_python-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b6e5aff95e3b9223068726e8d6bed1f11c8d715b03fb46a1f1e01f320054b5c
MD5 8b084acd29ead6421d18ff8216b5f55c
BLAKE2b-256 6d862c40f2579fa0b5fa1c60b72fcf2dce16a6b4cf46edfcb6aa3be95892e03f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page