Skip to content

Commit

Permalink
Merge bf73837 into 25c584c
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed May 1, 2020
2 parents 25c584c + bf73837 commit 103558a
Show file tree
Hide file tree
Showing 37 changed files with 1,642 additions and 268 deletions.
6 changes: 5 additions & 1 deletion .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ TESTS_ENVS=tests/_envs

CORE_BRANCH=develop
JWT_AUTH_BRANCH=develop
SKIP_TEST_CLEANUP=0
SKIP_TEST_CLEANUP=0
STRIPE_GATEWAY=1
GRAPHQL_JWT_AUTH_SECRET_KEY=testingtesting123
STRIPE_API_PUBLISHABLE_KEY=test_key
STRIPE_API_SECRET_KEY=test_secret
10 changes: 9 additions & 1 deletion .github/workflows/testing-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
pull_request:
branches:
- develop
- release/v0.5.1

jobs:
run:
Expand All @@ -27,6 +28,9 @@ jobs:
- php: '7.0'
wordpress: '5.0'
coverage: 1
- php: '7.3'
wordpress: '5.0'
debug: 1

exclude:
- php: '7.3'
Expand All @@ -39,7 +43,9 @@ jobs:
name: WordPress ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}

- name: Build "testing" Docker Image
run: |
Expand All @@ -52,6 +58,8 @@ jobs:
- name: Run Tests w/ Docker.
run: |
docker-compose run --rm \
-e STRIPE_API_PUBLISHABLE_KEY=${{ secrets.STRIPE_API_PUBLISHABLE_KEY }} \
-e STRIPE_API_SECRET_KEY=${{ secrets.STRIPE_API_SECRET_KEY }} \
-e COVERAGE=${{ matrix.coverage }} \
-e DEBUG=${{ matrix.debug }} \
testing --scale app=0
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/wordpress-coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
pull_request:
branches:
- develop
- release/v0.5.1

jobs:
run:
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ARG PHP_VERSION

FROM kidunot89/woographql-app:wp${WP_VERSION}-php${PHP_VERSION}


LABEL author=kidunot89
LABEL author_uri=https://github.com/kidunot89

Expand Down
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Requires PHP: 7.0
Requires WooCommerce: 3.0.0
Requires WPGraphQL: 0.8.0+
Works with WPGraphQL-JWT-Authentication: 0.4.0+
Stable tag: 0.4.4
Stable tag: 0.5.1
License: GPL-3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Maintained at: https://github.com/wp-graphql/wp-graphql-woocommerce
Expand Down
2 changes: 2 additions & 0 deletions bin/install-test-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ configure_wordpress() {
setup_woocommerce() {
echo "Installing & Activating WooCommerce"
wp plugin install woocommerce --activate
echo "Installing & Activating WooCommerce-Gateway-Stripe"
wp plugin install woocommerce-gateway-stripe --activate
}

setup_wpgraphql() {
Expand Down
3 changes: 3 additions & 0 deletions bin/testing-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ cd ${WP_ROOT_FOLDER}
# Run app entrypoint script.
. app-entrypoint.sh

# Deactivate WP-GraphQL-JWT-Authentication
wp plugin deactivate wp-graphql-jwt-authentication --allow-root

# Return to PWD.
echo "Moving back to project working directory."
cd ${workdir}
Expand Down
6 changes: 4 additions & 2 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ modules:
tablePrefix: '%WP_TABLE_PREFIX%'
domain: '%WP_DOMAIN%'
adminEmail: '%ADMIN_EMAIL%'
title: 'Test'
plugins:
title: 'Test'
plugins:
- woocommerce/woocommerce.php
- woocommerce-gateway-stripe/woocommerce-gateway-stripe.php
- wp-graphql/wp-graphql.php
- wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php
- wp-graphql-woocommerce/wp-graphql-woocommerce.php
activatePlugins:
- woocommerce/woocommerce.php
- woocommerce-gateway-stripe/woocommerce-gateway-stripe.php
- wp-graphql/wp-graphql.php
- wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php
- wp-graphql-woocommerce/wp-graphql-woocommerce.php
Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
"firebase/php-jwt": "^5.0"
},
"require-dev": {
"lucatume/wp-browser": ">=2.2.1 <2.2.8"
"lucatume/wp-browser": ">=2.2.1 <2.2.8",
"stripe/stripe-php": "^7.28"
},
"config": {
"optimize-autoloader": true
},
"autoload": {
"files":[
"files": [
"includes/connection/wc-cpt-connection-args.php",
"includes/functions.php"
],
Expand All @@ -42,6 +43,11 @@
"includes/"
]
},
"autoload-dev": {
"files": [
"tests/_data/config.php"
]
},
"scripts": {
"install-test-env": "bash bin/install-test-env.sh",
"test": "vendor/bin/codecept run",
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ services:
context: .
dockerfile: Dockerfile
args:
- PHP_VERSION="${PHP_VERSION:-7.3}"
- WP_VERSION="${WP_VERSION:-5.2}"
- PHP_VERSION=7.3
- WP_VERSION=5.2
- USE_XDEBUG
image: woographql-testing
volumes:
Expand Down
3 changes: 3 additions & 0 deletions includes/class-type-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,8 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) {
\WPGraphQL\WooCommerce\Mutation\Order_Delete::register_mutation();
\WPGraphQL\WooCommerce\Mutation\Order_Delete_Items::register_mutation();
\WPGraphQL\WooCommerce\Mutation\Checkout::register_mutation();
\WPGraphQL\WooCommerce\Mutation\Review_Write::register_mutation();
\WPGraphQL\WooCommerce\Mutation\Review_Update::register_mutation();
\WPGraphQL\WooCommerce\Mutation\Review_Delete_Restore::register_mutation();
}
}
25 changes: 24 additions & 1 deletion includes/class-woocommerce-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public static function setup() {
add_filter( 'graphql_response_headers_to_send', array( __CLASS__, 'add_session_header_to_expose_headers' ) );
add_filter( 'graphql_access_control_allow_headers', array( __CLASS__, 'add_session_header_to_allow_headers' ) );
}

// Add better support for Stripe payment gateway
add_filter( 'graphql_stripe_process_payment_args', array( __CLASS__, 'woographql_stripe_gateway_args' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -74,4 +77,24 @@ public static function add_session_header_to_allow_headers( array $allowed_heade
$allowed_headers[] = self::$session_header;
return $allowed_headers;
}
}

/**
* Adds extra arguments to the Stripe Gateway process payment call.
*
* @params array $gateway_args Arguments to be passed to the gateway `process_payment` method.
* @params string $payment_method Payment gateway ID.
*/
public static function woographql_stripe_gateway_args( $gateway_args, $payment_method ) {
if ( 'stripe' === $payment_method ) {
$gateway_args = array(
$gateway_args[0],
true,
false,
false,
true
);
}

return $gateway_args;
}
}
83 changes: 76 additions & 7 deletions includes/data/mutation/class-checkout-mutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ public static function prepare_checkout_args( $input, $context, $info ) {

foreach ( $fieldset as $field => $input_key ) {
$key = "{$fieldset_key}_{$field}";
$value = ! empty( $input[ $fieldset_key ][ $input_key ] )
? $input[ $fieldset_key ][ $input_key ]
: null;
if ( 'order' === $fieldset_key ) {
$value = ! empty( $input[ $input_key ] ) ? $input[ $input_key ] : null;
} else {
$value = ! empty( $input[ $fieldset_key ][ $input_key ] ) ? $input[ $fieldset_key ][ $input_key ] : null;
}

if ( $value ) {
$data[ $key ] = $value;
} elseif ( 'billing_country' === $key || 'shipping_country' === $key ) {
Expand Down Expand Up @@ -121,6 +124,7 @@ public static function get_checkout_fields( $fieldset = '', $prefixed = false )
'billing' => array(
'first_name' => 'firstName',
'last_name' => 'lastName',
'company' => 'company',
'address_1' => 'address1',
'address_2' => 'address2',
'city' => 'city',
Expand All @@ -133,6 +137,7 @@ public static function get_checkout_fields( $fieldset = '', $prefixed = false )
'shipping' => array(
'first_name' => 'firstName',
'last_name' => 'lastName',
'company' => 'company',
'address_1' => 'address1',
'address_2' => 'address2',
'city' => 'city',
Expand All @@ -144,7 +149,9 @@ public static function get_checkout_fields( $fieldset = '', $prefixed = false )
'username' => 'username',
'password' => 'password',
),
'order' => array(),
'order' => array(
'comments' => 'customerNote'
),
);

if ( $prefixed ) {
Expand Down Expand Up @@ -204,6 +211,48 @@ protected function update_session( $data ) {
WC()->cart->calculate_totals();
}

/**
* Clears customer address
*
* @param string $type Address type.
*
* @return bool
*/
protected static function clear_customer_address( $type = 'billing' ) {
if ( 'billing' !== $type && 'shipping' !== $type ) {
return false;
}

$address = array(
'first_name' => '',
'last_name' => '',
'company' => '',
'address_1' => '',
'address_2' => '',
'city' => '',
'state' => '',
'postcode' => '',
'country' => '',
);

if ( $type = 'billing' ) {
$address = array_merge(
$address,
array(
'email' => '',
'phone' => '',
)
);
}

foreach ( $address as $prop => $value ) {
$setter = "set_{$type}_{$prop}";
WC()->customer->{$setter}( $value );
}

return true;
}

/**
* Create a new customer account if needed.
*
Expand Down Expand Up @@ -459,8 +508,14 @@ protected function process_order_payment( $order_id, $payment_method ) {
// Store Order ID in session so it can be re-used after payment failure.
WC()->session->set( 'order_awaiting_payment', $order_id );

$process_payment_args = apply_filters(
"graphql_{$payment_method}_process_payment_args",
array( $order_id ),
$payment_method
);

// Process Payment.
return $available_gateways[ $payment_method ]->process_payment( $order_id );
return $available_gateways[ $payment_method ]->process_payment( ...$process_payment_args );
}

/**
Expand Down Expand Up @@ -502,11 +557,20 @@ public static function process_checkout( $data, $input, $context, $info, &$resul
do_action( 'woocommerce_before_checkout_process' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound

if ( WC()->cart->is_empty() ) {
throw new UserError( __( 'Sorry, your session has expired.', 'wp-graphql-woocommerce' ) );
throw new UserError( __( 'Sorry, no session found.', 'wp-graphql-woocommerce' ) );
}

do_action( 'woocommerce_checkout_process', $data, $context, $info ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound

if ( ! empty( $input['billing']['overwrite'] ) && true === $input['billing']['overwrite'] ) {
self::clear_customer_address( 'billing' );
}

if ( ! empty( $input['shipping'] ) && ! empty( $input['shipping']['overwrite'] )
&& true === $input['shipping']['overwrite'] ) {
self::clear_customer_address( 'shipping' );
}

// Update session for customer and totals.
self::update_session( $data );

Expand All @@ -525,6 +589,11 @@ public static function process_checkout( $data, $input, $context, $info, &$resul
throw new UserError( __( 'Unable to create order.', 'wp-graphql-woocommerce' ) );
}

// Add meta data.
if ( ! empty( $input['metaData'] ) ) {
self::add_order_meta( $order_id, $input['metaData'], $input, $context, $info );
}

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
do_action( 'woocommerce_checkout_order_processed', $order_id, $data, $order );

Expand Down Expand Up @@ -633,7 +702,7 @@ public static function add_order_meta( $order_id, $meta_data, $input, $context,

if ( $meta_data ) {
foreach ( $meta_data as $meta ) {
$order->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
$order->add_meta_data( $meta['key'], $meta['value'] );
}
}

Expand Down
9 changes: 4 additions & 5 deletions includes/mutation/class-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public static function get_input_fields() {
'type' => array( 'list_of' => 'MetaDataInput' ),
'description' => __( 'Order meta data', 'wp-graphql-woocommerce' ),
),
'customerNote' => array(
'type' => 'String',
'description' => __( 'Order customer note', 'wp-graphql-woocommerce' ),
)
);
}

Expand Down Expand Up @@ -146,11 +150,6 @@ public static function mutate_and_get_payload() {
throw new UserError( $order_id->get_error_message( 'checkout-error' ) );
}

// Add meta data.
if ( ! empty( $input['metaData'] ) ) {
Checkout_Mutation::add_order_meta( $order_id, $input['metaData'], $input, $context, $info );
}

/**
* Action called after checking out.
*
Expand Down
Loading

0 comments on commit 103558a

Please sign in to comment.