Skip to content

Instantly share code, notes, and snippets.

@Nicholas-Cardot
Created July 17, 2017 21:37
Show Gist options
  • Select an option

  • Save Nicholas-Cardot/24afd681d67094482580afc8631add7c to your computer and use it in GitHub Desktop.

Select an option

Save Nicholas-Cardot/24afd681d67094482580afc8631add7c to your computer and use it in GitHub Desktop.
Using a backup method for getting payments that allows for imported subscriptions
public function get_subscription( $ipn_data = array() ) {
$parent_payment_id = absint( $ipn_data['custom'] );
$backup_method = false;
// Check if we can find the payment via the internal EDD payment ID
if( !empty( $parent_payment_id ) ) {
$payment = edd_get_payment_by( 'id', $parent_payment_id );
if( ! $payment ) {
$backup_method = true;
}
} else {
$backup_method = true;
}
// Check if we can find the payment via the Gateway's generated transaction ID (Useful for imported subscriptions)
if( true === $backup_method ) {
$payment = edd_get_payment_by( 'transaction_id' , $ipn_data['txn_id'])
if( ! $payment ) {
return false;
}
}
@Nicholas-Cardot
Copy link
Author

Currently the EDD recurring payments plugins processes IPN requests in a way that does not allow for imported subscriptions (i.e. from WooCommerce subscriptions). This is because when the function that fetches the parent payment is used, it uses a payment ID that is generated internally by EDD and then passed over to PayPal during purchase which will come through the "custom" post parameter of the IPN notification.

The problem is that it is impossible to import a subscription in such a way that PayPal will know what should be in that "custom" post parameter for the new eCommerce platform.

However, this could easily be remedied to allow for imported subscriptions by using a backup method to check for the payment using the transaction ID field which is generated by PayPal (or other Gateways) and will therefore be the same and available on both WooCommerce Subscriptions and after the migration on EDD's platform.

In a nutshell:

First, check for the payment using the existing method by looking for the EDD generated payment ID.
Second, if the payment is not found, search for it using the gateway generated transaction ID.

The example above should hopefully accomplish this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment