-
Notifications
You must be signed in to change notification settings - Fork 4
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
7e6a84e
commit 3d16cb7
Showing
9 changed files
with
132 additions
and
84 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,19 +1,75 @@ | ||
document.addEventListener('vue:loaded', () => { | ||
window.app.$on('checkout-credentials-saved', () => { | ||
window.app.magentoCart('get', 'mollie/payment-token').then(response => { | ||
window.app.checkout.mollie = response | ||
}) | ||
}); | ||
|
||
window.app.$on('checkout-payment-saved', (data) => { | ||
if (!data.order.payment_method_code.includes('mollie_')) { | ||
return; | ||
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', (event) => { | ||
Vue.set(window.app.custom, 'mollie_selected_issuer', null) | ||
}); | ||
|
||
addBeforePaymentMethodHandler(async function (query, variables, options) { | ||
if (!variables.code.includes('mollie_') || !window?.app?.checkout?.mollie_selected_issuer) | ||
{ | ||
return [query, variables, options]; | ||
} | ||
|
||
// Add mollie_selected_issuer to setPaymentMethodOnCart | ||
query = config.queries.cart + | ||
` | ||
mutation setMolliePaymentMethodOnCart( | ||
$cart_id: String!, | ||
$code: String!, | ||
$mollie_selected_issuer: String | ||
) { | ||
setPaymentMethodOnCart(input: { | ||
cart_id: $cart_id, | ||
payment_method: { | ||
code: $code, | ||
mollie_selected_issuer: $mollie_selected_issuer | ||
} | ||
}) { | ||
cart { ...cart } | ||
} | ||
window.app.checkout.doNotGoToTheNextStep = true | ||
window.magentoAPI('post', 'mollie/transaction/start', { | ||
token: window.app.checkout.mollie | ||
}).then(response => { | ||
window.location.replace(response) | ||
}) | ||
}); | ||
}) | ||
}` | ||
|
||
variables.mollie_selected_issuer = window.app.custom.mollie_selected_issuer | ||
|
||
return [query, variables, options]; | ||
}); | ||
|
||
addBeforePlaceOrderHandler(async function (query, variables, options) { | ||
if (!cart.value?.selected_payment_method?.code?.includes('mollie_')) { | ||
return [query, variables, options]; | ||
} | ||
|
||
// Add mollie_return_url to placeorder | ||
query = config.queries.order + config.queries.orderV2 + | ||
` | ||
mutation molliePlaceOrder($cart_id: String!, $mollie_return_url: String) { | ||
placeOrder( | ||
input: { | ||
cart_id: $cart_id, | ||
mollie_return_url: $mollie_return_url | ||
} | ||
) { | ||
order { | ||
...order | ||
} | ||
orderV2 { | ||
...orderV2 | ||
} | ||
errors { | ||
code | ||
message | ||
} | ||
} | ||
}` | ||
|
||
variables.mollie_return_url = url('/checkout/success?payment_token={{payment_token}}'); | ||
|
||
return [query, variables, options] | ||
}); | ||
|
||
addAfterPlaceOrderHandler(async function (response, mutationComponent) { | ||
mutationComponent.redirect = response?.data?.placeOrder?.order?.mollie_redirect_url || mutationComponent.redirect; | ||
}); |
This file was deleted.
Oops, something went wrong.
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,5 +1,6 @@ | ||
mutation MollieProcessTransaction($payment_token: String!) { | ||
mollieProcessTransaction (input: { payment_token: $payment_token }) { | ||
paymentStatus | ||
redirect_to_success_page | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
<?php | ||
|
||
namespace Rapidez\Mollie\Actions; | ||
|
||
use Illuminate\Http\Client\RequestException; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
class CheckSuccessfulOrder | ||
{ | ||
/** | ||
* @throws RequestException | ||
*/ | ||
public function __invoke(Request $request) | ||
{ | ||
$paymentToken = $request->get('payment_token'); | ||
if (empty($paymentToken)) { | ||
return true; | ||
} | ||
|
||
$url = config('rapidez.magento_url').'/graphql'; | ||
|
||
$response = Http::post($url, [ | ||
'query' => view('mollie::graphql.process-transaction')->render(), | ||
'variables' => [ | ||
'payment_token' => $paymentToken, | ||
], | ||
])->throw()->object()->data; | ||
|
||
if ($response->mollieProcessTransaction && $response->mollieProcessTransaction->redirect_to_success_page) { | ||
return true; | ||
} | ||
|
||
// mollieProcessTransaction has already re-activated the cart for us. | ||
return false; | ||
} | ||
} |
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