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

Checkout mutation updates #229

Merged

Conversation

kidunot89
Copy link
Member

Your checklist for this pull request

Thanks for sending a pull request! Please make sure you click the link above to view the contribution guidelines, then fill out the blanks below.

🚨Please review the guidelines for contributing to this repository.

  • Make sure you are making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Make sure you are requesting to pull request from a topic/feature/bugfix branch (right side). Don't pull request from your master!

What does this implement/fix? Explain your changes.

  • Adds isPaid and transactionId fields added to CheckoutInput.
  • paymentMethodTitle field removed from CheckoutInput.
  • A transactionId is required for the prepaid order to be set to completed status.
    • This behavior can be alter by using the graphql_checkout_prepaid_order_validation filter.
/**
* Use this to do some last minute transaction ID validation.
*
* @param bool        $is_valid        Is transaction ID valid.
* @param WC_Order    $order           Order being processed.
* @param String|null $transaction_id  Order payment transaction ID.
* @param array       $data            Order data.
* @param array       $input           Order raw input data.
* @param AppContext  $context         Request's AppContext instance.
* @param ResolveInfo $info            Request's ResolveInfo instance.
*/
$valid = apply_filters(
   'graphql_checkout_prepaid_order_validation',
   ! empty( $input['transactionId'] ),
   $order,
   $transaction_id,
   $data,
   $input,
   $context,
   $info
);

Example checkout mutation

mutation checkout( $input: CheckoutInput! ) {
    checkout( input: $input ) {
        clientMutationId
        order {
           ...orderFields
        }
        customer {
           ...customerFields
        }
    }
}

new CheckoutInput definition

'clientMutationId' => array(
	'type'        => array( 'non_null' => 'String' ),
	'description' => __( 'Unique ID for mutation', 'wp-graphql-woocommerce' ),
),
'paymentMethod'          => array(
	'type'        => 'String',
	'description' => __( 'Payment method ID.', 'wp-graphql-woocommerce' ),
),
'shippingMethod'         => array(
	'type'        => 'String',
	'description' => __( 'Order shipping method', 'wp-graphql-woocommerce' ),
),
'shipToDifferentAddress' => array(
	'type'        => 'Boolean',
	'description' => __( 'Ship to a separate address', 'wp-graphql-woocommerce' ),
),
'billing'                => array(
	'type'        => 'CustomerAddressInput',
	'description' => __( 'Order billing address', 'wp-graphql-woocommerce' ),
),
'shipping'               => array(
	'type'        => 'CustomerAddressInput',
	'description' => __( 'Order shipping address', 'wp-graphql-woocommerce' ),
),
'account'                => array(
	'type'        => 'CreateAccountInput',
	'description' => __( 'Create new customer account', 'wp-graphql-woocommerce' ),
),
'transactionId'          => array(
	'type'        => 'String',
	'description' => __( 'Order transaction ID', 'wp-graphql-woocommerce' ),
),
'isPaid'                 => array(
	'type'        => 'Boolean',
	'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'wp-graphql-woocommerce' ),
),
'metaData'               => array(
	'type'        => array( 'list_of' => 'MetaDataInput' ),
	'description' => __( 'Order meta data', 'wp-graphql-woocommerce' ),
),

Does this close any currently open issues?

#226

Any relevant logs, error output, GraphiQL screenshots, etc?

(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)

Any other comments?

Where has this been tested?

Operating System: Linux Mint 19.2

WordPress Version: 5.3.2

@kidunot89 kidunot89 added enhancement New feature or request bugfix Implements bugfix labels Feb 3, 2020
@kidunot89 kidunot89 requested a review from jasonbahl February 3, 2020 16:43
@kidunot89 kidunot89 self-assigned this Feb 3, 2020
@kidunot89 kidunot89 mentioned this pull request Feb 3, 2020
@kidunot89 kidunot89 merged commit e5ed555 into wp-graphql:develop Feb 4, 2020
@kidunot89 kidunot89 deleted the bugfix/prepaid-checkout-support branch February 4, 2020 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Implements bugfix enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant