Skip to content

Commit

Permalink
Merge pull request #161 from pooliestudios/paypal-v2
Browse files Browse the repository at this point in the history
Paypal v2
  • Loading branch information
jvarelmann authored Jan 21, 2025
2 parents 69a6784 + c8d81c2 commit ac8d7e9
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion assets/build/blocks.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wc-blocks-checkout', 'wc-blocks-registry', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'bf2b5aa05d052bad880a');
<?php return array('dependencies' => array('wc-blocks-checkout', 'wc-blocks-registry', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '7d66adfab2d89f43fd03');
2 changes: 1 addition & 1 deletion assets/build/blocks.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions client/blocks/paypal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ export default getPaymentMethodConfig(
'bs_payone_paypal',
__('PAYONE PayPal', 'payone-woocommerce-3'),
`${PAYONE_ASSETS_URL}/icon-paypal.png`,
null,
{
canMakePayment() {
const {paypalConfig} = wc.wcSettings.getSetting('payone_data');
return paypalConfig.isAvailable;
},
},
);
18 changes: 11 additions & 7 deletions client/blocks/paypalv2/express.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ const PayPalV2Express = () => {
label: 'paypal',
height: 55,
},
createOrder(data, actions) {
console.log('createOrder', data, actions);
return fetch('', {
createOrder() {
return fetch(paypalExpressConfig.callbackUrl, {
method: 'post',
}).then((res) => {
return res.text();
}).then((orderID) => {
return orderID;
});
},
onApprove(data, actions) {
console.log('onApprove', data, actions);
window.location = '';
onApprove() {
window.location = paypalExpressConfig.redirectUrl;
},
}).render('#payone-paypalv2-express-button');
}
Expand All @@ -47,10 +45,16 @@ const PayPalV2Express = () => {

export default getPaymentMethodConfig(
'payone_paypalv2_express',
__('PAYONE PayPal v2 Express', 'payone-woocommerce-3'),
__('PayPal v2 Express', 'payone-woocommerce-3'),
icon,
<PayPalV2Express />,
{
gatewayId: 'payone_paypalv2_express',
canMakePayment() {
return false;

const {paypalExpressConfig} = wc.wcSettings.getSetting('payone_data');
return paypalExpressConfig.isAvailable;
},
},
);
7 changes: 5 additions & 2 deletions src/Payone/Gateway/PayoneBlocksSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,14 @@ public function get_payment_method_data() {
'urlSecuredInstallment' => Plugin::get_callback_url( [ 'type' => 'ajax-secured-installment-options' ] ),
];
$data['paypalExpressConfig'] = [
'jsUrl' => 'https://www.paypal.com/sdk/js?client-id='.$this->paypalV2ExpressGateway->get_payone_client_id().'&merchant-id='.$this->paypalV2ExpressGateway->get_payone_merchant_id().'&currency=EUR&intent=authorize&locale=de_DE&commit=false&vault=false&disable-funding=card,sepa,bancontact&enable-funding=paylater',
'jsUrl' => 'https://www.paypal.com/sdk/js?client-id='.$this->paypalV2ExpressGateway->get_payone_client_id().'&merchant-id='.$this->paypalV2ExpressGateway->get_payone_merchant_id().'&currency=EUR&intent=authorize&locale=de_DE&commit=false&vault=false&disable-funding=card,sepa,bancontact'.( $this->paypalV2ExpressGateway->get_allow_paylater() ? '&enable-funding=paylater' : ''),
'callbackUrl' => Plugin::get_callback_url( [ 'type' => 'paypalv2', 'a' => 'express-set-checkout' ] ),
'redirectUrl' => Plugin::get_callback_url( [ 'type' => 'paypalv2', 'a' => 'express-get-checkout' ] ),
'isAvailable' => $this->paypalV2ExpressGateway->is_available(),
];
$data['paypalConfig'] = [
'isAvailable' => Plugin::find_gateway(PayPal::GATEWAY_ID)->is_available(),
];


// TODO: installmentMonthOptions müssen hier befüllt werden
$data['installmentMonthOptions'] = [
Expand Down
2 changes: 1 addition & 1 deletion src/Payone/Transaction/AmazonPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function execute( \WC_Order $order ) {
if ( $this->should_submit_cart() ) {
$this->add_article_list_to_transaction( $order );
}
$this->set( 'reference', uniqid( 'ref', false) );
$this->set_reference( $order );
$this->set_once( 'amount', $order->get_total('edit') * 100 );
$this->set( 'currency', strtoupper( get_woocommerce_currency() ) );
$this->set_personal_data_from_order( $order );
Expand Down
2 changes: 1 addition & 1 deletion src/Payone/Transaction/AmazonPayExpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function execute( \WC_Order $order ) {
if ( $this->should_submit_cart() ) {
$this->add_article_list_to_transaction( $order );
}
$this->set( 'reference', uniqid( 'ref', false) );
$this->set_reference( $order );
$this->set_once( 'amount', $order->get_total('edit') * 100 );
$this->set( 'currency', strtoupper( get_woocommerce_currency() ) );
$this->set_personal_data_from_order( $order );
Expand Down
2 changes: 1 addition & 1 deletion src/Payone/Transaction/PayPalV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function execute( \WC_Order $order ) {
if ( $this->should_submit_cart() ) {
$this->add_article_list_to_transaction( $order );
}
$this->set( 'reference', uniqid( 'ref', false) );
$this->set_reference( $order );
$this->set_once( 'amount', $order->get_total('edit') * 100 );
$this->set( 'currency', strtoupper( get_woocommerce_currency() ) );
$this->set_personal_data_from_order( $order );
Expand Down
2 changes: 1 addition & 1 deletion src/Payone/Transaction/PayPalV2Express.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct( $gateway ) {
*/
public function execute( \WC_Order $order ) {
$this->add_article_list_to_transaction( $order );
$this->set( 'reference', uniqid( 'ref', false) );
$this->set_reference( $order );
$this->set_once( 'amount', $order->get_total('edit') * 100 );
$this->set( 'currency', strtoupper( get_woocommerce_currency() ) );
$this->set_personal_data_from_order( $order );
Expand Down

0 comments on commit ac8d7e9

Please sign in to comment.