Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.8] feat: payment profile, BC vault substitution #2032

Draft
wants to merge 11 commits into
base: development
Choose a base branch
from
122 changes: 122 additions & 0 deletions app/GraphQL/Souk/Mutations/Orders/OrderManagementMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Kanvas\Social\Interactions\DataTransferObject\UserInteraction;
use Kanvas\Souk\Orders\DataTransferObject\DirectOrder;
use Kanvas\Souk\Payments\DataTransferObject\CreditCard;
use Kanvas\Souk\Payments\DataTransferObject\Profile;
use Kanvas\Souk\Payments\DataTransferObject\Transaction;
use Kanvas\Souk\Payments\Providers\AuthorizeNetPaymentProcessor;

class OrderManagementMutation
Expand Down Expand Up @@ -42,6 +44,126 @@ public function create(mixed $root, array $request): array
return $this->handlePaymentResponse($response, $isSubscription);
}

public function createCustomerProfileWithPayment(mixed $root, array $request)
{
$user = auth()->user();
$creditCard = CreditCard::viaRequest($request['input']);
$profile = Profile::viaRequest($request['input']);
$cart = app('cart')->session($user->getId());

$order = new DirectOrder(
app(Apps::class),
$user,
$creditCard,
$cart,
$profile
);

$payment = new AuthorizeNetPaymentProcessor(
app(Apps::class),
auth()->user()->getCurrentBranch()
);

return $payment->createCustomerProfileWithPayment($order);
}

public function createCustomerPaymentProfile(mixed $root, array $request)
{
$user = auth()->user();
$creditCard = CreditCard::viaRequest($request['input']);
$profile = Profile::viaRequest($request['input']);
$cart = app('cart')->session($user->getId());

$order = new DirectOrder(
app(Apps::class),
$user,
$creditCard,
$cart,
$profile
);


$payment = new AuthorizeNetPaymentProcessor(
app(Apps::class),
auth()->user()->getCurrentBranch()
);

return $payment->createCustomerPaymentProfile($order);
}

public function updateCustomerPaymentProfile(mixed $root, array $request)
{
$user = auth()->user();
$creditCard = CreditCard::viaRequest($request['input']);
$profile = Profile::viaRequest($request['input']);
$cart = app('cart')->session($user->getId());

$order = new DirectOrder(
app(Apps::class),
$user,
$creditCard,
$cart,
$profile
);


$payment = new AuthorizeNetPaymentProcessor(
app(Apps::class),
auth()->user()->getCurrentBranch()
);

return $payment->updateCustomerPaymentProfile($order);
}

public function deleteCustomerPaymentProfile(mixed $root, array $request)
{
$user = auth()->user();
$creditCard = CreditCard::viaRequest($request['input']);
$profile = Profile::viaRequest($request['input']);
$cart = app('cart')->session($user->getId());

$order = new DirectOrder(
app(Apps::class),
$user,
$creditCard,
$cart,
$profile
);


$payment = new AuthorizeNetPaymentProcessor(
app(Apps::class),
auth()->user()->getCurrentBranch()
);

return $payment->deleteCustomerPaymentProfile($order);
}

public function refundPayment(mixed $root, array $request)
{
$user = auth()->user();
$creditCard = CreditCard::viaRequest($request['input']);
$transaction = Transaction::viaRequest($request['input']);
$cart = app('cart')->session($user->getId());

$order = new DirectOrder(
app(Apps::class),
$user,
$creditCard,
$cart,
null,
$transaction
);


$payment = new AuthorizeNetPaymentProcessor(
app(Apps::class),
auth()->user()->getCurrentBranch()
);

return $payment->refundPayment($order);
}

private function processPayment(DirectOrder $order, bool $isSubscription): mixed
{
$payment = new AuthorizeNetPaymentProcessor(
Expand Down
32 changes: 32 additions & 0 deletions graphql/schemas/Souk/order.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,22 @@ input CartOrderInput {
note: String
}

input ProfileInput {
customerProfileId: ID!
customerPaymentProfileId: ID!
}

input TransactionInput {
transactionId: ID!
amount: Float!
}

input OrderInput {
cartId: ID!
payment: CreditCardInput!
billing: CreditCardBillingInput
profile: ProfileInput
transaction: TransactionInput
}

input DraftOrderInput {
Expand Down Expand Up @@ -121,6 +133,26 @@ extend type Mutation @guard {
@field(
resolver: "App\\GraphQL\\Souk\\Mutations\\Orders\\OrderManagementMutation@create"
)
createCustomerProfileWithPayment(input: OrderInput!): Mixed!
@field(
resolver: "App\\GraphQL\\Souk\\Mutations\\Orders\\OrderManagementMutation@createCustomerProfileWithPayment"
)
createCustomerPaymentProfile(input: OrderInput!): Mixed!
@field(
resolver: "App\\GraphQL\\Souk\\Mutations\\Orders\\OrderManagementMutation@createCustomerPaymentProfile"
)
updateCustomerPaymentProfile(input: OrderInput!): Mixed!
@field(
resolver: "App\\GraphQL\\Souk\\Mutations\\Orders\\OrderManagementMutation@updateCustomerPaymentProfile"
)
deleteCustomerPaymentProfile(input: OrderInput!): Mixed!
@field(
resolver: "App\\GraphQL\\Souk\\Mutations\\Orders\\OrderManagementMutation@deleteCustomerPaymentProfile"
)
refundPayment(input: OrderInput!): Mixed!
@field(
resolver: "App\\GraphQL\\Souk\\Mutations\\Orders\\OrderManagementMutation@refundPayment"
)
createDraftOrder(input: DraftOrderInput!): Order!
@field(
resolver: "App\\GraphQL\\Souk\\Mutations\\Orders\\DraftOrderManagementMutation@create"
Expand Down
6 changes: 5 additions & 1 deletion src/Domains/Souk/Orders/DataTransferObject/DirectOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Darryldecode\Cart\Cart;
use Kanvas\Apps\Models\Apps;
use Kanvas\Souk\Payments\DataTransferObject\CreditCard;
use Kanvas\Souk\Payments\DataTransferObject\Profile;
use Kanvas\Souk\Payments\DataTransferObject\Transaction;
use Kanvas\Users\Models\Users;
use Spatie\LaravelData\Data;

Expand All @@ -16,7 +18,9 @@ public function __construct(
public Apps $app,
public Users $user,
public CreditCard $creditCard,
public Cart $cart
public Cart $cart,
public ?Profile $profile = null,
public ?Transaction $transaction = null
) {
}
}
27 changes: 27 additions & 0 deletions src/Domains/Souk/Payments/DataTransferObject/Profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Kanvas\Souk\Payments\DataTransferObject;

use Illuminate\Support\Arr;
use Spatie\LaravelData\Data;

class Profile extends Data
{
public function __construct(
public readonly int $customerProfileId,
public readonly int $customerPaymentProfileId,
) {
}

public static function viaRequest(array $orderInput): self
{
$profileData = Arr::get($orderInput, 'profile', []);

return new self(
$profileData['customerProfileId'],
$profileData['customerPaymentProfileId'],
);
}
}
27 changes: 27 additions & 0 deletions src/Domains/Souk/Payments/DataTransferObject/Transaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Kanvas\Souk\Payments\DataTransferObject;

use Illuminate\Support\Arr;
use Spatie\LaravelData\Data;

class Transaction extends Data
{
public function __construct(
public readonly int $transactionId,
public readonly float $amount,
) {
}

public static function viaRequest(array $orderInput): self
{
$transactionData = Arr::get($orderInput, 'transaction', []);

return new self(
$transactionData['transactionId'],
$transactionData['amount']
);
}
}
Loading
Loading