Skip to content

Commit

Permalink
Merge branch 'main' into php81
Browse files Browse the repository at this point in the history
  • Loading branch information
dortort committed May 23, 2023
2 parents f726866 + a53d11a commit 5ac428c
Show file tree
Hide file tree
Showing 28 changed files with 1,442 additions and 186 deletions.
185 changes: 185 additions & 0 deletions .github/workflows/update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
name: Updates SDK based on api-definitions

on:
workflow_dispatch:
inputs:
trigger-reason:
description: |
The comment that will be posted to the PR if any changes are added.
Used to provide context about the source of the update.
required: false

jobs:
build-api-definitions:
runs-on: ubuntu-latest
steps:
- name: Checkout api-definitions repo
uses: actions/checkout@v2
with:
repository: 'Rebilly/api-definitions'

- name: Install api-definitions dependencies
run: npm install

- name: Build api-definitions
run: npm run build

- name: Upload built definitions
uses: actions/upload-artifact@v2
with:
name: definitions
path: dist
retention-days: 1
if-no-files-found: error

generate-sdk:
runs-on: ubuntu-latest
needs: build-api-definitions
strategy:
matrix:
api: ['core', 'user']
steps:
- name: Prepare variables
id: prep
run: |
OPENAPI_URI=""
SERVICE_NAME=""
MAPPING_SEGMENT="core"
if [[ "${{ matrix.api }}" == "core" ]]; then
OPENAPI_URI="/definitions/core.yaml"
SERVICE_NAME="CoreService"
fi
if [[ "${{ matrix.api }}" == "user" ]]; then
OPENAPI_URI="/definitions/users.yaml"
SERVICE_NAME="UserService"
fi
echo ::set-output name=openapi-uri::${OPENAPI_URI}
echo ::set-output name=service-name::${SERVICE_NAME}
echo ::set-output name=mapping-segment::${MAPPING_SEGMENT}
echo ::group::Variables
echo "OpenAPI URI: ${OPENAPI_URI}"
echo "Service name: ${SERVICE_NAME}"
echo "Mapping segment: ${MAPPING_SEGMENT}"
echo ::endgroup::
- name: Login to registry
run: |
echo ${{ secrets.MACHINE_USER_PAT }} | docker login ghcr.io --username ${{ github.actor }} --password-stdin
- name: Download definitions
uses: actions/download-artifact@v3
with:
name: definitions
path: /tmp/definitions/

- name: Build SDK
run: |
docker run --rm \
-v "/tmp/${{ matrix.api }}-sdk:/out" \
-v "/tmp/definitions:/definitions" \
ghcr.io/rebilly/php-sdk-generator:latest generate \
-g rebilly-php \
-o /out \
-c /config.yaml \
-i "${{ steps.prep.outputs.openapi-uri }}" \
--additional-properties=serviceName=${{ steps.prep.outputs.service-name }} \
--additional-properties=resourceMapping=./shared/custom-resource-mapping.json \
--additional-properties=resourceMappingSegment=${{ steps.prep.outputs.mapping-segment }}
- name: Compress SDK
working-directory: /tmp
run: |
zip -r ${{ matrix.api }}-sdk.zip ${{ matrix.api }}-sdk \
-x ${{ matrix.api }}-sdk/.openapi-generator/\* \
-x ${{ matrix.api }}-sdk/.openapi-generator-ignore
- name: Upload SDK
uses: actions/upload-artifact@v3
with:
name: sdk-separate
path: /tmp/${{ matrix.api }}-sdk.zip
retention-days: 1
if-no-files-found: error

bundle-sdk:
runs-on: ubuntu-latest
needs: generate-sdk
steps:
- uses: actions/checkout@v2
with:
ref: 'v3.0-dev'
path: 'sdk'

- uses: actions/checkout@v2
with:
path: 'generator'
repository: 'Rebilly/rebilly-sdk-generator'

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, intl, curl, json
tools: composer:v2

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Download generated API SDKs
uses: actions/download-artifact@v3
with:
name: sdk-separate
path: /tmp/generated/

- name: Decompress SDKs
working-directory: /tmp/generated
run: unzip \*.zip

- name: Merge APIs files
run: |
rm -rf sdk/{tests,src,composer.json,.php-cs-fixer.php} && \
php ./generator/php/merge-apis.php ./sdk /tmp/generated/*-sdk
- name: Install composer dependencies
working-directory: ./sdk
run: composer install --prefer-dist

- name: CS fix SDK
working-directory: ./sdk
run: composer cs-fix

- name: Create PR
id: cpr
uses: peter-evans/create-pull-request@v3
with:
# Path of the checked-out repo where we placed the generated resources
path: 'sdk'
token: ${{ secrets.MACHINE_USER_PAT }}
title: 'chore: update SDK from api-definitions'
commit-message: update SDK from api-definitions
branch: automations/update-sdk-from-api-definitions
base: v3.0-dev
# Delete the branch when closing PRs or merging
delete-branch: true
body: This PR is automatically generated and updates SDK based on a change in the API definitions

- name: Comment trigger reason
uses: marocchino/sticky-pull-request-comment@v2
if: |
(steps.cpr.outputs.pull-request-operation == 'created' ||
steps.cpr.outputs.pull-request-operation == 'updated') &&
github.event.inputs.trigger-reason != ''
with:
GITHUB_TOKEN: ${{ secrets.MACHINE_USER_PAT }}
append: true
number: ${{ steps.cpr.outputs.pull-request-number }}
message: |
Triggered due to: ${{ github.event.inputs.trigger-reason }}
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,46 @@ Security - in case of vulnerabilities.

_TBD_

## [2.20.0] 2023-05-22

### Added

- [x] Added new property to `Subscription`: `paymentInstrumentId`
- [x] Added new property to `CreditMemo`: `allocations`
- [x] Added `CreditMemoService::patch()` method
- [x] Added `SubscriptionService::getUpcomingInvoice()` method
- [x] Added `PaymentCardInstrument::getPaymentInstrumentId` method
- [x] Added `PaymentCardInstrument::setPaymentInstrumentId` method
- [x] Added `AchInstrument::getPaymentInstrumentId` method
- [x] Added `AchInstrument::setPaymentInstrumentId` method
- [x] Added `PayPalInstrument::getPaymentInstrumentId` method
- [x] Added `PayPalInstrument::setPaymentInstrumentId` method

### Fixed

- [x] Added missing `subscriptionPauses` service in Client

### Deprecated

- [x] Deprecated `SubscriptionService::getUpcomingInvoices()` method
- [x] Deprecated `PaymentCardInstrument::getPaymentCardId` method
- [x] Deprecated `PaymentCardInstrument::setPaymentCardId` method
- [x] Deprecated `AchInstrument::getBankAccountId` method
- [x] Deprecated `AchInstrument::setBankAccountId` method
- [x] Deprecated `PayPalInstrument::getPayPalAccountId` method
- [x] Deprecated `PayPalInstrument::setPayPalAccountId` method

### Removed

- [x] Removed `UserService` methods: `resetPassword`, `resetTotp`, `updatePassword`
- [x] Removed `ResetPassword`, `UpdatePassword` entities

## [2.19.0] 2022-06-22

### Added

- [x] Added **Credit Memos API**.

## [2.18.0] 2022-04-21

### Added
Expand Down
8 changes: 7 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
* @method Services\CustomerCredentialService customerCredentials()
* @method Services\CustomerService customers()
* @method Services\InvoiceItemService invoiceItems()
* @method Services\CreditMemoAllocationService creditMemoAllocations()
* @method Services\InvoiceService invoices()
* @method Services\CreditMemoService creditMemos()
* @method Services\PaymentCardService paymentCards()
* // TODO: Deprecated factory
* @method Services\PaymentTokenService paymentCardTokens()
Expand Down Expand Up @@ -90,6 +92,7 @@
* @method Services\AmlService aml()
* @method Services\PaymentInstrumentService paymentInstruments()
* @method Services\TagService tags()
* @method Services\SubscriptionPauseService subscriptionPauses()
*/
final class Client
{
Expand All @@ -102,7 +105,7 @@ final class Client
*/
public const CURRENT_VERSION = 'v2.1';

public const SDK_VERSION = '2.18.0';
public const SDK_VERSION = '2.20.0';

private static $services = [
'authenticationOptions' => Services\AuthenticationOptionsService::class,
Expand All @@ -112,7 +115,9 @@ final class Client
'customerCredentials' => Services\CustomerCredentialService::class,
'customers' => Services\CustomerService::class,
'invoiceItems' => Services\InvoiceItemService::class,
'creditMemoAllocations' => Services\CreditMemoAllocationService::class,
'invoices' => Services\InvoiceService::class,
'creditMemos' => Services\CreditMemoService::class,
'paymentCards' => Services\PaymentCardService::class,
'paymentCardTokens' => Services\PaymentTokenService::class,
'paymentTokens' => Services\PaymentTokenService::class,
Expand Down Expand Up @@ -155,6 +160,7 @@ final class Client
'taxjarCredentials' => Services\TaxJarCredentialsService::class,
'paymentInstruments' => Services\PaymentInstrumentService::class,
'tags' => Services\TagService::class,
'subscriptionPauses' => Services\SubscriptionPauseService::class,
];

/** @var array */
Expand Down
64 changes: 64 additions & 0 deletions src/Entities/AllocationCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* This source file is proprietary and part of Rebilly.
*
* (c) Rebilly SRL
* Rebilly Ltd.
* Rebilly Inc.
*
* @see https://www.rebilly.com
*/

namespace Rebilly\Entities;

use Rebilly\Rest\Entity;

/**
* Class AllocationCollection.
*/
final class AllocationCollection extends Entity
{
/**
* @param array $data
*
* @return AllocationCollection
*/
public static function createFromData(array $data)
{
return new self($data);
}

/**
* @return TransactionAllocation[]
*/
public function getTransactions()
{
return $this->getAttribute('transactions');
}

/**
* @param TransactionAllocation[] $value
*
* @return $this
*/
public function setTransactions($value)
{
return $this->setAttribute('transactions', $value);
}

/**
* @param array $data
*
* @return array|TransactionAllocation[]
*/
public function createTransactions(array $data)
{
return array_map(function ($item) {
if ($item instanceof TransactionAllocation) {
return $item;
}

return new TransactionAllocation($item);
}, $data);
}
}

0 comments on commit 5ac428c

Please sign in to comment.