Skip to content

Commit

Permalink
Merge pull request #1 from dystcz/0.5
Browse files Browse the repository at this point in the history
Upgrade to Lunar API 0.5
  • Loading branch information
lorinczdev committed Sep 23, 2023
2 parents f1cea7a + 2748df9 commit cb7ff18
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 116 deletions.
4 changes: 0 additions & 4 deletions .env.testing.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ APP_URL=http://localhost
DB_CONNECTION="sqlite"
DB_DATABASE=":memory:"

REDIS_HOST=redis
REDIS_PASSWORD=secret_redis
REDIS_PORT=6379

PAYMENT_DRIVER=paypal

#PayPal API Mode
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none

- name: Install composer dependencies
Expand Down
51 changes: 0 additions & 51 deletions .github/workflows/run-tests.yml

This file was deleted.

59 changes: 59 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Tests

on:
pull_request:
jobs:
build:

runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [ 8.2 ]
laravel: [ 10 ]

environment: testing

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Laravel environment
run: |
cp .env.testing.example .env.testing
sed -i 's/PAYPAL_SANDBOX_CLIENT_ID=/PAYPAL_SANDBOX_CLIENT_ID=${{ secrets.PAYPAL_SANDBOX_CLIENT_ID }}/g' .env.testing
sed -i 's/PAYPAL_SANDBOX_CLIENT_SECRET=/PAYPAL_SANDBOX_CLIENT_SECRET=${{ secrets.PAYPAL_SANDBOX_CLIENT_SECRET }}/g' .env.testing
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, bcmath
tools: composer:v2
coverage: none
ini-values: error_reporting=E_ALL

- name: Set Laravel Version
run: composer require "laravel/framework:^${{ matrix.laravel }}" --no-update

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

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
restore-keys: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/pest
File renamed without changes.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ testbench.yaml
vendor
node_modules
.env.testing
.lando.yml
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This is my package lunar-api-paypal-adapter
# Lunar API Paypal Adapter

[![Latest Version on Packagist](https://img.shields.io/packagist/v/dystcz/lunar-api-paypal-adapter.svg?style=flat-square)](https://packagist.org/packages/dystcz/lunar-api-paypal-adapter)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/dystcz/lunar-api-paypal-adapter/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/dystcz/lunar-api-paypal-adapter/actions?query=workflow%3Arun-tests+branch%3Amain)
![GitHub Actions](https://github.com/dystcz/lunar-api-paypal-adapter/actions/workflows/tests.yaml/badge.svg)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/dystcz/lunar-api-paypal-adapter/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/dystcz/lunar-api-paypal-adapter/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/dystcz/lunar-api-paypal-adapter.svg?style=flat-square)](https://packagist.org/packages/dystcz/lunar-api-paypal-adapter)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
TODO: Write description

## Installation

Expand Down
32 changes: 9 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"description": "This is my package lunar-api-paypal-adapter",
"keywords": [
"dystcz",
"lunar",
"lunar-api",
"lunar-api-paypal-adapter",
"laravel",
"lunar-api-paypal-adapter"
"php"
],
"homepage": "https://github.com/dystcz/lunar-api-paypal-adapter",
"license": "MIT",
Expand All @@ -15,20 +18,10 @@
"role": "Developer"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/dystcz/lunar-api.git"
},
{
"type": "vcs",
"url": "https://github.com/dystcz/lunar-paypal.git"
}
],
"require": {
"php": "^8.1",
"dystcz/lunar-api": "dev-feature/payment-gateways-adapters",
"dystcz/lunar-paypal": "dev-main",
"php": "^8.2",
"dystcz/lunar-api": "^0.5",
"dystcz/lunar-paypal": "^0.5.0",
"illuminate/contracts": "^10.0",
"spatie/laravel-package-tools": "^1.14.0"
},
Expand All @@ -48,14 +41,12 @@
},
"autoload": {
"psr-4": {
"Dystcz\\LunarApiPaypalAdapter\\": "src/",
"Dystcz\\LunarApiPaypalAdapter\\Database\\Factories\\": "database/factories/"
"Dystcz\\LunarApiPaypalAdapter\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Dystcz\\LunarApiPaypalAdapter\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/"
"Dystcz\\LunarApiPaypalAdapter\\Tests\\": "tests/"
}
},
"scripts": {
Expand All @@ -66,11 +57,6 @@
"@composer run prepare",
"@php vendor/bin/testbench workbench:build --ansi"
],
"start": [
"Composer\\Config::disableProcessTimeout",
"@composer run build",
"@php vendor/bin/testbench serve"
],
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/AuthorizePaypalPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __invoke(Order $order): void
$payment = Payments::driver('paypal')
->cart($order->cart)
->withData([
'payment_intent' => $order->meta->payment_intent,
'payment_intent' => $order->meta['payment_intent'],
])
->authorize();

Expand Down
5 changes: 4 additions & 1 deletion tests/CreatePaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Dystcz\LunarApi\Domain\Carts\Models\Cart;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Lunar\Facades\CartSession;

beforeEach(function () {
Event::fake(CartCreated::class);
Expand All @@ -14,6 +15,8 @@
->withLines()
->create();

CartSession::use($cart);

$this->order = $cart->createOrder();
$this->cart = $cart;
});
Expand All @@ -38,6 +41,6 @@
$response->assertSuccessful();

expect($response->json('meta.payment_intent.id'))
->toBe($this->cart->fresh()->meta->payment_intent);
->toBe($this->cart->fresh()->meta['payment_intent']);
})
->with(['paypal']);
8 changes: 5 additions & 3 deletions tests/HandlePaypalWebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
],
]);

$cart->createOrder();
$cart->shippingAddress->delete();

$cart->order->update([
$order = $cart->createOrder();

$order->update([
'meta' => [
'payment_intent' => $this->payment_intent_id,
],
]);

$this->cart = $cart;
$this->order = $cart->order;
$this->order = $order;
});

it('can handle succeeded event', function () {
Expand Down
2 changes: 0 additions & 2 deletions tests/Stubs/Carts/Modifiers/TestShippingModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class TestShippingModifier extends ShippingModifier

public function handle(Cart $cart)
{
$cart->load(['shippingAddress', 'shippingAddress.country']);

ShippingManifest::addOption(
new ShippingOption(
name: 'Basic Delivery',
Expand Down
13 changes: 0 additions & 13 deletions tests/Stubs/Users/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

namespace Dystcz\LunarApiPaypalAdapter\Tests\Stubs\Users;

use Dystcz\LunarApi\Domain\Users\Factories\UserFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Lunar\Base\Traits\LunarUser;

class User extends Authenticatable
{
use HasFactory;
use LunarUser;
use LunarUser;
use Notifiable;
Expand Down Expand Up @@ -44,14 +41,4 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];

/**
* Return a new factory instance for the model.
*
* @return \Lunar\Tests\Stubs\UserFactory
*/
protected static function newFactory(): UserFactory
{
return UserFactory::new();
}
}
30 changes: 16 additions & 14 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dystcz\LunarApiPaypalAdapter\Tests;

use Cartalyst\Converter\Laravel\ConverterServiceProvider;
use Dystcz\LunarApi\JsonApiServiceProvider;
use Dystcz\LunarApi\LunarApiServiceProvider;
use Dystcz\LunarApiPaypalAdapter\LunarApiPaypalAdapterServiceProvider;
Expand All @@ -15,23 +14,17 @@
use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Kalnoy\Nestedset\NestedSetServiceProvider;
use LaravelJsonApi\Spec\ServiceProvider;
use LaravelJsonApi\Testing\MakesJsonApiRequests;
use Livewire\LivewireServiceProvider;
use Lunar\Base\ShippingModifiers;
use Lunar\Facades\Taxes;
use Lunar\LunarServiceProvider;
use Lunar\Models\Channel;
use Lunar\Models\Country;
use Lunar\Models\Currency;
use Lunar\Models\CustomerGroup;
use Lunar\Models\TaxClass;
use Orchestra\Testbench\TestCase as Orchestra;
use Spatie\Activitylog\ActivitylogServiceProvider;
use Spatie\LaravelBlink\BlinkServiceProvider;
use Spatie\LaravelData\LaravelDataServiceProvider;
use Spatie\MediaLibrary\MediaLibraryServiceProvider;

class TestCase extends Orchestra
{
Expand Down Expand Up @@ -81,15 +74,15 @@ protected function getPackageProviders($app)
// Laravel JsonApi
\LaravelJsonApi\Encoder\Neomerx\ServiceProvider::class,
\LaravelJsonApi\Laravel\ServiceProvider::class,
ServiceProvider::class,
\LaravelJsonApi\Spec\ServiceProvider::class,

// Lunar core
LunarServiceProvider::class,
MediaLibraryServiceProvider::class,
ActivitylogServiceProvider::class,
ConverterServiceProvider::class,
NestedSetServiceProvider::class,
BlinkServiceProvider::class,
\Lunar\LunarServiceProvider::class,
\Spatie\MediaLibrary\MediaLibraryServiceProvider::class,
\Spatie\Activitylog\ActivitylogServiceProvider::class,
\Cartalyst\Converter\Laravel\ConverterServiceProvider::class,
\Kalnoy\Nestedset\NestedSetServiceProvider::class,
\Spatie\LaravelBlink\BlinkServiceProvider::class,

// Lunar Paypal
LunarPaypalServiceProvider::class,
Expand Down Expand Up @@ -140,6 +133,15 @@ public function getEnvironmentSetUp($app)
'prefix' => '',
]);

// Default payment driver
Config::set('lunar.payments.default', 'paypal');
Config::set('lunar.payments.types', [
'paypal' => [
'driver' => 'paypal',
'authorized' => 'payment-stripe',
],
]);

Config::set('lunar.paypal', require __DIR__.'/../vendor/dystcz/lunar-paypal/config/paypal.php');
}

Expand Down

0 comments on commit cb7ff18

Please sign in to comment.