public static function handleRedirectReturn($data = false) { $connections = CASHSystem::getSystemSettings('system_connections'); if (isset($connections['com.amazon'])) { $s3_default_email = $connections['com.amazon']['email']; } else { $s3_default_email = false; } $success = S3Seed::connectAndAuthorize($data['key'], $data['secret'], $data['bucket'], $s3_default_email); if ($success) { // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth // calls would only happen in the admin. If this changes we can f**k around with it later. $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $connection_name = $data['bucket'] . ' (Amazon S3)'; if (substr($connection_name, 0, 10) == 'cashmusic.') { $connection_name = 'Amazon S3 (created ' . date("M j, Y") . ')'; } $result = $new_connection->setSettings($connection_name, 'com.amazon', array('bucket' => $data['bucket'])); if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.'); } } else { //$return_markup = '<h4>Error</h4>' // . '<p>We couldn\'t connect with your S3 account. Please check the key and secret.</p>'; AdminHelper::formFailure('We couldn\'t connect your S3 account. Please check the key and secret.'); } return $return_markup; }
function __construct() { echo "Testing Paypal Seed\n"; // add a new admin user for this $user_add_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => '*****@*****.**', 'password' => 'thiswillneverbeused', 'is_admin' => 1)); $this->cash_user_id = $user_add_request->response['payload']; // add a new connection $this->paypal_username = getTestEnv("PAYPAL_USERNAME"); if (!$this->paypal_username) { echo "Paypal credentials not found, skipping tests\n"; } $c = new CASHConnection($this->cash_user_id); // the '1' sets a user id=1 $this->paypal_connection_id = $c->setSettings('Paypal', 'com.paypal', array("username" => $this->paypal_username, "password" => getTestEnv("PAYPAL_PASSWORD"), "signature" => getTestEnv("PAYPAL_SIGNATURE"), "sandboxed" => true)); }
function __construct() { // add a new admin user for this $user_add_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => '*****@*****.**', 'password' => 'thiswillneverbeused', 'is_admin' => 1)); $this->cash_user_id = $user_add_request->response['payload']; // add a new connection $this->api_key = getTestEnv("MAILCHIMP_API_KEY"); $c = new CASHConnection($this->cash_user_id); // the '1' sets a user id=1 $this->mailchimp_connection_id = $c->setSettings('MailChimp', 'com.mailchimp', array("key" => $this->api_key, "list" => $this->test_id)); // add a new list $list_add_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'addlist', 'name' => 'Test List', 'description' => 'Test Description', 'user_id' => $this->cash_user_id, 'connection_id' => $this->mailchimp_connection_id)); // should work fine with no description or connection_id $this->test_list_id = $list_add_request->response['payload']; }
function __construct() { echo "Testing S3 Seed\n"; // add a new admin user for this $user_add_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => '*****@*****.**', 'password' => 'thiswillneverbeused', 'is_admin' => 1)); $this->cash_user_id = $user_add_request->response['payload']; $this->timestamp = time(); $this->s3_key = getTestEnv("S3_KEY"); $this->s3_bucket = getTestEnv("S3_BUCKET"); if (!$this->s3_key) { echo "S3 credentials not found, skipping tests\n"; } // add a new connection $c = new CASHConnection($this->cash_user_id); $this->s3_connection_id = $c->setSettings('S3', 'com.amazon', array("key" => $this->s3_key, "secret" => getTestEnv("S3_SECRET"), "bucket" => $this->s3_bucket)); }
function testAuth() { if ($this->s3_key) { $s3 = new S3Seed($this->cash_user_id, $this->s3_connection_id); $starting_acp = $s3->getAccessControlPolicy($this->s3_bucket); $this->assertTrue(is_array($starting_acp)); $second_email = getTestEnv("S3_2_EMAIL"); $second_key = getTestEnv("S3_2_KEY"); $second_secret = getTestEnv("S3_2_SECRET"); if ($second_email && $second_key && $second_secret) { $auth_success = $s3->authorizeEmailForBucket($this->s3_bucket, $second_email); $this->assertTrue($auth_success); $changed_acp = $s3->getAccessControlPolicy($this->s3_bucket); $this->assertNotEqual($starting_acp, $changed_acp); // add a new connection for the second user $c = new CASHConnection($this->cash_user_id); $new_connection_id = $c->setSettings('S32', 'com.amazon', array("key" => $second_key, "secret" => $second_secret, "bucket" => $this->s3_bucket)); if ($new_connection_id) { $s32 = new S3Seed($this->cash_user_id, $new_connection_id); // now test that we do in fact have upload permission // go through the range of tests — upload, delete, verify $test_filename = dirname(__FILE__) . '/test' . $this->timestamp; $tmp_file = file_put_contents($test_filename, $this->timestamp); $result = $s32->uploadFile($test_filename, false, false); $this->assertTrue($result); $result = $s32->deleteFile('test' . $this->timestamp); $this->assertTrue($result); $full_list = $s32->listAllFiles(); $this->assertFalse(array_key_exists('test' . $this->timestamp, $full_list)); unlink(dirname(__FILE__) . '/test' . $this->timestamp); unset($s32); $acp_success = $s3->setAccessControlPolicy($this->s3_bucket, '', $starting_acp); $this->assertTrue($acp_success); $changed_acp = $s3->getAccessControlPolicy($this->s3_bucket); $this->assertEqual($starting_acp, $changed_acp); } else { echo 'problem adding second S3Seed'; } } } }
new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'addaddresstolist', 'address' => $person[0], 'list_id' => $list_id, 'first_name' => $person[1], 'last_name' => $person[2], 'initial_comment' => $person[3], 'do_not_verify' => true)); } $cr = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'addasset', 'title' => 'Sample release', 'description' => 'This is a sample release. I\'m sorry I thought that was sort of obvious.', 'parent_id' => 0, 'user_id' => 1, 'type' => 'release')); // $cr->response['payload'] will be the release id $release_id = $cr->response['payload']; $cr = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'addasset', 'title' => 'Sample release cover', 'description' => 'This is the cover for the sample release. See?', 'parent_id' => $release_id, 'location' => 'http://*****:*****@testmedia.com', 'onesheet' => 'Test bio'); // add the cover to the release new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'editasset', 'id' => $release_id, 'metadata' => $release_metadata)); $cr = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'addasset', 'title' => 'Sample file (dog badges)', 'description' => 'Dogs are awesome.', 'parent_id' => 0, 'location' => 'http://*****:*****@buyer.com","PAYERID":"KW2MPO2RWV4SW","PAYERSTATUS":"verified","FIRSTNAME":"Fake","LASTNAME":"McTest","COUNTRYCODE":"US","CURRENCYCODE":"USD","AMT":"5.99","ITEMAMT":"5.99","SHIPPINGAMT":"0.00","HANDLINGAMT":"0.00","TAXAMT":"0.00","DESC":"Sample item","INSURANCEAMT":"0.00","SHIPDISCAMT":"0.00","L_NAME0":"Sample item","L_NUMBER0":"order-6","L_QTY0":"1","L_TAXAMT0":"0.00","L_AMT0":"5.99","L_ITEMWEIGHTVALUE0":" 0.00000","L_ITEMLENGTHVALUE0":" 0.00000","L_ITEMWIDTHVALUE0":" 0.00000","L_ITEMHEIGHTVALUE0":" 0.00000","PAYMENTREQUEST_0_CURRENCYCODE":"USD","PAYMENTREQUEST_0_AMT":"5.99","PAYMENTREQUEST_0_ITEMAMT":"5.99","PAYMENTREQUEST_0_SHIPPINGAMT":"0.00","PAYMENTREQUEST_0_HANDLINGAMT":"0.00","PAYMENTREQUEST_0_TAXAMT":"0.00","PAYMENTREQUEST_0_DESC":"Sample item","PAYMENTREQUEST_0_INSURANCEAMT":"0.00","PAYMENTREQUEST_0_SHIPDISCAMT":"0.00","PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED":"false","L_PAYMENTREQUEST_0_NAME0":"Sample item","L_PAYMENTREQUEST_0_NUMBER0":"order-6","L_PAYMENTREQUEST_0_QTY0":"1","L_PAYMENTREQUEST_0_TAXAMT0":"0.00","L_PAYMENTREQUEST_0_AMT0":"23.00","L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE0":" 0.00000","L_PAYMENTREQUEST_0_ITEMLENGTHVALUE0":" 0.00000","L_PAYMENTREQUEST_0_ITEMWIDTHVALUE0":" 0.00000","L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE0":" 0.00000"}', 'data_returned' => '{"TOKEN":"EC-3CC324611K842411K","SUCCESSPAGEREDIRECTREQUESTED":"false","TIMESTAMP":"2014-10-02T19:16:26Z","CORRELATIONID":"11a6663cxo30d","ACK":"Success","VERSION":"63.0","BUILD":"3719653","INSURANCEOPTIONSELECTED":"false","SHIPPINGOPTIONISDEFAULT":"false","PAYMENTINFO_0_TRANSACTIONID":"4WN12370L1021013D","PAYMENTINFO_0_TRANSACTIONTYPE":"expresscheckout","PAYMENTINFO_0_PAYMENTTYPE":"instant","PAYMENTINFO_0_ORDERTIME":"2014-10-02T19:16:23Z","PAYMENTINFO_0_AMT":"5.99","PAYMENTINFO_0_FEEAMT":"0.35","PAYMENTINFO_0_TAXAMT":"0.00","PAYMENTINFO_0_CURRENCYCODE":"USD","PAYMENTINFO_0_PAYMENTSTATUS":"Completed","PAYMENTINFO_0_PENDINGREASON":"None","PAYMENTINFO_0_REASONCODE":"None","PAYMENTINFO_0_PROTECTIONELIGIBILITY":"Ineligible","PAYMENTINFO_0_ERRORCODE":"0","PAYMENTINFO_0_ACK":"Success"}', 'successful' => 1, 'gross_price' => 5.99, 'service_fee' => 0.35, 'currency' => 'USD', 'status' => 'complete')); // id in $cr->response['payload'] $cust = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => '*****@*****.**', 'password' => 'whocares', 'first_name' => 'Fake', 'last_name' => 'McTest', 'display_name' => 'Fake McTest')); $ord = new CASHRequest(array('cash_request_type' => 'commerce', 'cash_action' => 'addorder', 'user_id' => 1, 'customer_user_id' => $cust->response['payload'], 'transaction_id' => $cr->response['payload'], 'order_contents' => array(array('id' => 1, 'user_id' => 1, 'name' => 'Sample item', 'description' => 'This is a description for the test item.', 'sku' => '#abc123', 'price' => '5.99', 'flexible_price' => 0, 'digital_fulfillment' => 1, 'physical_fulfillment' => 0, 'physical_weight' => 0, 'physical_width' => 0, 'physical_height' => 0, 'physical_depth' => 0, 'available_units' => -1, 'variable_pricing' => 0, 'fulfillment_asset' => 1, 'descriptive_asset' => 0, 'creation_date' => time())), 'fulfilled' => 0, 'canceled' => 0, 'physical' => 0, 'digital' => 1, 'notes' => '', 'country_code' => 'US', 'currency' => 'USD', 'element_id' => 1)); // this is silly, but we need to edit the order to get a positive "modification_date" // in the table — easiest way to test for abandoned/non-abandoned. will probably be // changing that behavior later. new CASHRequest(array('cash_request_type' => 'commerce', 'cash_action' => 'editorder', 'id' => $ord->response['payload'], 'fulfilled' => 1)); $cr = new CASHRequest(array('cash_request_type' => 'calendar', 'cash_action' => 'addvenue', 'name' => 'Tiga', 'city' => 'Portland', 'region' => 'OR')); $venue_id = $cr->response['payload']; new CASHRequest(array('cash_request_type' => 'calendar', 'cash_action' => 'addevent', 'date' => 1388534400, 'user_id' => 1, 'venue_id' => $venue_id, 'published' => 1, 'comment' => 'past event')); new CASHRequest(array('cash_request_type' => 'calendar', 'cash_action' => 'addevent', 'date' => time() + 5184000, 'user_id' => 1, 'venue_id' => $venue_id, 'published' => 1, 'comment' => 'coming event')); $cr = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'addelement', 'name' => 'Test element', 'type' => 'emailcollection', 'options_data' => array('message_invalid_email' => 'Sorry, that email address wasn\'t valid. Please try again.', 'message_privacy' => 'We won\'t share, sell, or be jerks with your email address.', 'message_success' => 'Thanks! You\'re all signed up.', 'email_list_id' => $list_id, 'asset_id' => $file_id, 'comment_or_radio' => 0, 'do_not_verify' => 1), 'user_id' => 1)); ?> <h1>Success. There's a whole bunch of junk stuffed in there now.</h1>
public static function handleRedirectReturn($data = false) { if (!isset($data['state'])) { return "Please start the Dropbox authentication flow from the beginning."; } $connections = CASHSystem::getSystemSettings('system_connections'); if (!isset($connections['com.dropbox'])) { return 'Please add default Dropbox credentials.'; } $auth_client = DropboxSeed::getWebAuthClient($connections['com.dropbox']['redirect_uri']); try { list($token, $user_id) = $auth_client->finish($data); } catch (Exception $e) { $token = false; } if (!$token) { return "The Dropbox authentication flow failed - please try again."; } $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings($user_id . ' (Dropbox)', 'com.dropbox', array('access_token' => $token, 'user_id' => $user_id)); if (!$result) { $settings_for_user = $new_connection->getAllConnectionsforUser(); if (is_array($settings_for_user)) { foreach ($settings_for_user as $key => $connection_data) { if ($connection_data['name'] == $user_id . ' (Dropbox)') { $result = $connection_data['id']; break; } } } } if (isset($data['return_result_directly'])) { return $result; } else { if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/settings/connections/'); } } }
public static function handleRedirectReturn($data = false) { if (isset($data['error'])) { return 'There was an error. (general) Please try again.'; } else { $connections = CASHSystem::getSystemSettings('system_connections'); require_once CASH_PLATFORM_ROOT . '/lib/twitter/OAuth.php'; require_once CASH_PLATFORM_ROOT . '/lib/twitter/twitteroauth.php'; $temporary_credentials = AdminHelper::getPersistentData('twitter_temporary_credentials'); $twitter = new TwitterOAuth($connections['com.twitter']['client_id'], $connections['com.teitter']['client_secret'], $temporary_credentials['oauth_token'], $temporary_credentials['oauth_token_secret']); $access_token = $twitter->getAccessToken($_REQUEST['oauth_verifier']); if ($twitter->http_code == 200) { // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth // calls would only happen in the admin. If this changes we can f**k around with it later. $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings('@' . $access_token['screen_name'] . ' (Twitter)', 'com.twitter', array('token' => $access_token)); if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Could not save connection.', '/settings/connections/'); } } else { AdminHelper::formFailure('Error. Problem communicating with Twitter', '/settings/connections/'); } } }
public static function handleRedirectReturn($data = false) { if (isset($data['code'])) { $connections = CASHSystem::getSystemSettings('system_connections'); if (isset($connections['com.google.drive'])) { $credentials = GoogleDriveSeed::exchangeCode($data['code'], $connections['com.google.drive']['client_id'], $connections['com.google.drive']['client_secret'], $connections['com.google.drive']['redirect_uri']); $user_info = GoogleDriveSeed::getUserInfo($credentials, $connections['com.google.drive']['client_id'], $connections['com.google.drive']['client_secret']); if ($user_info) { $email_address = $user_info['email']; $user_id = $user_info['id']; } else { $email_address = false; $user_id = false; } $credentials_array = json_decode($credentials, true); if (isset($credentials_array['refresh_token'])) { // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth // calls would only happen in the admin. If this changes we can f**k around with it later. $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings($email_address . ' (Google Drive)', 'com.google.drive', array('user_id' => $user_id, 'email_address' => $email_address, 'access_token' => $credentials, 'access_expires' => $credentials_array['created'] + $credentials_array['expires_in'], 'refresh_token' => $credentials_array['refresh_token'])); if (!$result) { $settings_for_user = $new_connection->getAllConnectionsforUser(); if (is_array($settings_for_user)) { foreach ($settings_for_user as $key => $connection_data) { if ($connection_data['name'] == $email_address . ' (Google Drive)') { $result = $connection_data['id']; break; } } } } if (isset($data['return_result_directly'])) { return $result; } else { if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/settings/connections/'); } } } else { return 'Could not find a refresh token from google'; } } else { return 'Please add default google drive app credentials.'; } } else { return 'There was an error. (session) Please try again.'; } }
if (array_key_exists($settings_type, $settings_types_data)) { $cash_admin->page_data['state_markup'] = '<h4>' . $settings_types_data[$settings_type]['name'] . '</h4><p>' . $settings_types_data[$settings_type]['instructions'] . '</p>'; $cash_admin->page_data['state_markup'] .= '<form method="post" action="">' . '<input type="hidden" name="dosettingsadd" value="makeitso" />' . '<input type="hidden" name="settings_type" value="' . $settings_type . '" />' . '<label for="settings_name">Connection name</label>' . '<input type="text" id="settings_name" name="settings_name" placeholder="Give It A Name" /><br />'; foreach ($settings_types_data[$settings_type]['dataTypes'][$cash_admin->platform_type] as $key => $data) { $cash_admin->page_data['state_markup'] .= '<label for="' . $key . '">' . $key . '</label>' . '<input type="text" id="' . $key . '" name="' . $key . '" placeholder="' . ucfirst($key) . '" />'; } $cash_admin->page_data['state_markup'] .= '<div class="row_seperator"></div><br />' . '<div><input class="button" type="submit" value="Add The Connection" /></div>' . '</form>'; } else { $cash_admin->page_data['state_markup'] = '<h4>Error</h4><p>The requested setting type could not be found.</p>'; } } else { $settings_data_array = array(); foreach ($settings_types_data[$settings_type]['dataTypes'][$cash_admin->platform_type] as $key => $data) { $settings_data_array[$key] = $_POST[$key]; } $result = $page_data_object->setSettings($_POST['settings_name'], $_POST['settings_type'], $settings_data_array); if ($result) { // postConnection hook if (method_exists($seed_name, 'postConnection')) { $_POST['settings_id'] = $result; $_POST['user_id'] = $cash_admin->effective_user_id; $_POST['settings_type'] = $settings_type; $_POST['settings_name'] = $settings_name; $seed_name::postConnection($_POST); } $cash_admin->page_data['action_message'] = '<strong>Success.</strong> Everything was added successfully. You\'ll see it in your list of connections.'; } else { $cash_admin->page_data['action_message'] = '<strong>Error.</strong> Something went wrong. Please make sure you\'re using a unique name for this connection. Not only is that just smart, it\'s required.'; } } } else {
public static function handleRedirectReturn($data = false) { if (!isset($data['key'])) { return 'There was an error. (general) Please try again.'; } else { require_once CASH_PLATFORM_ROOT . '/lib/mandrill/Mandrill.php'; $m = new Mandrill($data['key']); $user_info = $m->getUserInfo(); $username = $user_info['username']; // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth // calls would only happen in the admin. If this changes we can f**k around with it later. $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings($username . ' (Mandrill)', 'com.mandrillapp', array('key' => $data['key'])); if (!$result) { return 'There was an error. (adding the connection) Please try again.'; } // set up webhooks $api_credentials = CASHSystem::getAPICredentials(); $webhook_api_url = CASH_API_URL . '/verbose/people/processwebhook/origin/com.mandrillapp/api_key/' . $api_credentials['api_key']; //$m->webhooksDelete($webhook_api_url); // remove duplicate webhooks //$m->webhooksAdd($webhook_api_url,array('send','hard_bounce','soft_bounce','open','click','spam','unsub','reject')); // add it, all events $m->call('webhooks/add', array("url" => $webhook_api_url, "events" => array('hard_bounce', 'soft_bounce', 'open', 'click', 'spam', 'unsub', 'reject'))); if (isset($data['return_result_directly'])) { return $result; } else { if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.'); } } } }