-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5044ec0
commit 353be04
Showing
5 changed files
with
102 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,44 @@ | ||
import { token } from 'Vendor/rapidez/core/resources/js/stores/useUser' | ||
import { mask } from 'Vendor/rapidez/core/resources/js/stores/useMask' | ||
import { cart } from 'Vendor/rapidez/core/resources/js/stores/useCart' | ||
import { addBeforePaymentMethodHandler, addBeforePlaceOrderHandler, addAfterPlaceOrderHandler } from 'Vendor/rapidez/core/resources/js/stores/usePaymentHandlers' | ||
|
||
document.addEventListener('vue:loaded', () => { | ||
async function placeOrder() { | ||
if (!token.value && window.app.guestEmail) { | ||
await window.magentoGraphQL( | ||
`mutation setGuestEmailOnCart($cart_id: String!, $email: String!) { | ||
setGuestEmailOnCart(input: { | ||
cart_id: $cart_id | ||
email: $email | ||
}) { | ||
cart { | ||
} | ||
} | ||
}`, | ||
{ | ||
cart_id: mask.value, | ||
email: window.app.guestEmail | ||
} | ||
) | ||
} | ||
|
||
await window.magentoGraphQL( | ||
`mutation setRivertyPaymentMethodOnCart( | ||
$cart_id: String! | ||
$code: String! | ||
$terms_and_conditions: Int! | ||
$customer_dob: String | ||
$customer_gender: Int | ||
$customer_telephone: String | ||
) { | ||
setPaymentMethodOnCart( | ||
input: { | ||
cart_id: $cart_id | ||
payment_method: { | ||
code: $code | ||
afterpay: { | ||
customer_dob: $customer_dob | ||
customer_gender: $customer_gender | ||
customer_telephone: $customer_telephone | ||
terms_and_conditions: $terms_and_conditions | ||
} | ||
} | ||
} | ||
) { | ||
cart { | ||
selected_payment_method { | ||
code | ||
} | ||
} | ||
} | ||
}`, | ||
{ | ||
cart_id: mask.value, | ||
code: window.app.checkout.payment_method, | ||
terms_and_conditions: 1, | ||
customer_gender: window.app.custom?.gender ?? window.app.checkout.billing_address?.gender ?? window.app.checkout.shipping_address?.gender, | ||
customer_dob: window.app.custom?.dob ?? window.app.checkout.billing_address?.dob ?? window.app.checkout.shipping_address?.dob ?? window.app.checkout.billing_address?.date_of_birth ?? window.app.checkout.shipping_address?.date_of_birth ?? '1999-11-11', | ||
customer_telephone: window.app.checkout.billing_address?.telephone ?? window.app.checkout.shipping_address?.telephone | ||
} | ||
) | ||
addBeforePaymentMethodHandler(async function (query, variables, options) { | ||
if (!variables.code.includes('riverty_') && !variables.code.includes('afterpay_')) { | ||
return [query, variables, options]; | ||
} | ||
|
||
return await window.magentoGraphQL( | ||
`mutation rivertyPlaceOrder($cart_id: String!) { | ||
placeOrder( | ||
input: { | ||
cart_id: $cart_id | ||
} | ||
) { | ||
order { | ||
order_number | ||
} | ||
errors { | ||
code | ||
message | ||
} | ||
// Add afterpay data to setPaymentMethodOnCart | ||
query = config.queries.cart + | ||
` | ||
mutation setRivertyPaymentMethodOnCart( | ||
$cart_id: String! | ||
$code: String! | ||
$terms_and_conditions: Int! | ||
$customer_dob: String | ||
$customer_gender: Int | ||
$customer_telephone: String | ||
) { | ||
setPaymentMethodOnCart( | ||
input: { | ||
cart_id: $cart_id | ||
payment_method: { | ||
code: $code | ||
afterpay: { | ||
customer_dob: $customer_dob | ||
customer_gender: $customer_gender | ||
customer_telephone: $customer_telephone | ||
terms_and_conditions: $terms_and_conditions | ||
} | ||
}`, | ||
{ | ||
'cart_id': mask.value | ||
} | ||
).then(response => { | ||
if (response?.data?.placeOrder?.order?.order_number) { | ||
return true; | ||
} | ||
|
||
if (response?.data?.placeOrder?.errors) { | ||
response?.data?.placeOrder?.errors?.forEach((error) => Notify(error.message)); | ||
} | ||
|
||
return false; | ||
}) | ||
} | ||
|
||
window.app.$on('before-checkout-payment-saved', (data) => { | ||
if (!data.order.payment_method_code.includes('riverty_') && !data.order.payment_method_code.includes('afterpay_')) { | ||
return; | ||
) { | ||
cart { ...cart } | ||
} | ||
window.app.checkout.preventOrder = true | ||
window.app.checkout.doNotGoToTheNextStep = true | ||
}` | ||
|
||
variables.terms_and_conditions = 1 | ||
variables.customer_gender = window.app.custom?.gender ?? cart.value?.billing_address?.gender ?? cart.value?.shipping_address?.gender | ||
variables.customer_dob = window.app.custom?.dob ?? cart.value?.billing_address?.dob ?? cart.value?.shipping_address?.dob ?? cart.value?.billing_address?.date_of_birth ?? cart.value?.shipping_address?.date_of_birth ?? '1999-11-11' | ||
variables.customer_telephone = cart.value?.billing_address?.telephone ?? cart.value?.shipping_address?.telephone | ||
|
||
placeOrder(data).then(success => success ? window.app.checkout.step = window.app.getCheckoutStep('success') : ''); | ||
}); | ||
}) | ||
return [query, variables, options]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,41 @@ | ||
<div v-if="checkout.payment_method.includes('riverty_') || checkout.payment_method.includes('afterpay_')" class="mt-2"> | ||
<span class="my-1">@lang('In order to use Riverty to pay, we need the following information.')</span> | ||
<x-rapidez::label :label="__('Date of Birth')" class="my-1"> | ||
<x-rapidez::input | ||
name="dob" | ||
type="date" | ||
v-model="$root.custom.dob" | ||
<template v-else-if="method.code.includes('riverty_') || method.code.includes('afterpay_')"> | ||
<x-rapidez::radio | ||
name="payment_method" | ||
v-model="variables.code" | ||
v-bind:value="method.code" | ||
v-bind:dusk="'method-'+index" | ||
v-on:change="mutate" | ||
required | ||
> | ||
</x-rapidez::input> | ||
</x-rapidez::label> | ||
<x-rapidez::label :label="__('Gender')" class="my-1"> | ||
<div class="flex"> | ||
<x-rapidez::radio | ||
name="gender" | ||
value="1" | ||
v-model="$root.custom.gender" | ||
@{{ method.title }} | ||
</x-rapidez::radio> | ||
<div class="mt-2" v-if="variables.code === method.code"> | ||
<span class="my-1">@lang('In order to use Riverty to pay, we need the following information.')</span> | ||
<x-rapidez::label :label="__('Date of Birth')" class="my-1"> | ||
<x-rapidez::input | ||
name="dob" | ||
type="date" | ||
v-model="$root.custom.dob" | ||
> | ||
<div>@lang('Male')</div> | ||
</x-rapidez::radio> | ||
<x-rapidez::radio | ||
name="gender" | ||
value="2" | ||
v-model="$root.custom.gender" | ||
> | ||
<div>@lang('Female')</div> | ||
</x-rapidez::radio> | ||
</div> | ||
</x-rapidez::label> | ||
</div> | ||
</x-rapidez::input> | ||
</x-rapidez::label> | ||
<x-rapidez::label :label="__('Gender')" class="my-1"> | ||
<div class="flex"> | ||
<x-rapidez::radio | ||
name="gender" | ||
value="1" | ||
v-model="$root.custom.gender" | ||
> | ||
<div>@lang('Male')</div> | ||
</x-rapidez::radio> | ||
<x-rapidez::radio | ||
name="gender" | ||
value="2" | ||
v-model="$root.custom.gender" | ||
> | ||
<div>@lang('Female')</div> | ||
</x-rapidez::radio> | ||
</div> | ||
</x-rapidez::label> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Rapidez\Riverty\View\Composers; | ||
|
||
use Illuminate\View\View; | ||
|
||
class PaymentMethodComposer | ||
{ | ||
/** | ||
* Create a new profile composer. | ||
*/ | ||
public function __construct() {} | ||
|
||
/** | ||
* Bind data to the view. | ||
*/ | ||
public function compose(View $view): void | ||
{ | ||
$view->getFactory()->startPush('payment_methods', view('riverty::additional-info')->render()); | ||
} | ||
} |