diff --git a/Libraries/VaahAjax.php b/Libraries/VaahAjax.php index 05ebff9..befdbc3 100644 --- a/Libraries/VaahAjax.php +++ b/Libraries/VaahAjax.php @@ -14,7 +14,38 @@ public function __construct() $this->ajax = new Client(); } //------------------------------------------------ - public function post($url, $params=null, $headers = null) + public function get($url, $query=null, $headers = null): array + { + $data = null; + + if(!is_null($query)) + { + $data['query'] = $query; + } + if(!is_null($headers)) + { + $data['headers'] = $headers; + } + try{ + $res = $this->ajax->request('GET', $url, $data); + $response = [ + 'status' => 'success', + 'data' => [ + 'status_code' => $res->getStatusCode(), + 'body' => $res->getBody(), + 'content' => $res->getBody()->getContents(), + ] + ]; + }catch(\Exception $e) + { + $response['status'] = 'failed'; + $response['errors'] = [$e->getMessage()]; + + } + return $response; + } + //------------------------------------------------ + public function post($url, $params=null, $headers = null): array { $data = null; diff --git a/Libraries/VaahApollo.php b/Libraries/VaahApollo.php new file mode 100644 index 0000000..7d2d043 --- /dev/null +++ b/Libraries/VaahApollo.php @@ -0,0 +1,79 @@ +api_base_url = $api_base_url; + $this->api_key = $api_key; + } + //---------------------------------------------------------- + + public function getOrganizations($inputs ) + { + $url = $this->api_base_url."organizations/enrich"; + $ajax = new VaahAjax(); + $headers = []; + $inputs['api_key'] = $this->api_key; + + $res = $ajax->post($url, $inputs, $headers); + + unset($inputs['api_key']); + + $response['request'] = $inputs; + $response['response'] = $res; + + return $response; + } + //---------------------------------------------------------- + public function getPeople($inputs) + { + + $url = $this->api_base_url."mixed_people/search"; + + $ajax = new VaahAjax(); + $headers = [ + 'Content-Type' => 'application/json' + ]; + + $inputs['api_key'] = $this->api_key; + + if(isset($inputs['domains'])){ + if(is_array($inputs['domains']) && count($inputs['domains']) > 0){ + $inputs['q_organization_domains'] = implode("\n", $inputs['domains']); + }else if(is_string($inputs['domains'])){ + $inputs['q_organization_domains'] = preg_replace('/^www\./', '', $inputs['domains']); + } + } + + + /* + * person_titles variable accept query string like + * person_titles[]=ceo&person_titles[]=cto + * which is not equal to php array, hence we have to convert it + */ + + $apollo_inputs = http_build_query($inputs); + $apollo_inputs = preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', $apollo_inputs); + + $res = $ajax->get($url, $apollo_inputs, $headers); + + unset($inputs['api_key']); + $response['request'] = $inputs; + $response['response'] = $res; + + return $response; + } + //---------------------------------------------------------- + + +} diff --git a/Libraries/VaahImap.php b/Libraries/VaahImap.php index 6eab815..164c0d5 100644 --- a/Libraries/VaahImap.php +++ b/Libraries/VaahImap.php @@ -61,7 +61,7 @@ function test(): array return $response; } //---------------------------------------------------------- - function connect($search_by='SINCE', $search_value=null) + function connect() { $response = $this->test(); @@ -71,10 +71,6 @@ function connect($search_by='SINCE', $search_value=null) return $response; } - if($search_by=='SINCE' && !$search_value){ - $search_value = date('d F Y'); - } - $this->imap = new \PhpImap\Mailbox( $this->mailbox, $this->username, @@ -88,6 +84,18 @@ function connect($search_by='SINCE', $search_value=null) $this->imap->setAttachmentsIgnore(true); } + return $this->imap; + } + //---------------------------------------------------------- + function searchMailBox($search_by='UNSEEN', $search_value=null){ + + $this->connect(); + + if($search_by === 'SINCE' && is_null($search_value)) + { + $search_value = date('d F Y'); + } + try { if($search_by == 'SINCE') { @@ -97,6 +105,21 @@ function connect($search_by='SINCE', $search_value=null) } else{ $this->mail_uids = $this->searchMailBox('UNSEEN', SE_UID); } + + if(count($this->mail_uids) < 1) { + $response = [ + 'status' => "success", + 'data' => [], + 'messages' => ['Mailbox is empty'], + ]; + return $response; + } + + return [ + 'status' => "success", + 'data' => $this->mail_uids + ]; + } catch(\PhpImap\ConnectionException $ex) { $response = [ @@ -107,21 +130,30 @@ function connect($search_by='SINCE', $search_value=null) } - if(count($this->mail_uids) < 1) { - $response = [ - 'status' => "success", - 'data' => [], - 'messages' => ['Mailbox is empty'], - ]; - return $response; + + } + //---------------------------------------------------------- + function getMailUids($search_by='UNSEEN', $search_value=null) + { + + $connect = $this->searchMailBox($search_by, $search_value); + + if(isset($connect['status']) && $connect['status'] == 'failed') + { + return $connect; } + $response = [ + 'status' => "success", + 'data' => $this->mail_uids, + ]; + return $response; } //---------------------------------------------------------- function getMails($search_by='SINCE', $search_value=null) { - $connect = $this->connect($search_by, $search_value); + $connect = $this->searchMailBox($search_by, $search_value); if(isset($connect['status']) && $connect['status'] == 'failed') { @@ -155,6 +187,9 @@ function getMails($search_by='SINCE', $search_value=null) //---------------------------------------------------------- function getMail($uid) { + + $this->connect(); + $mail = $this->imap->getMail($uid); $data['mail_uid'] = $uid; @@ -167,15 +202,15 @@ function getMail($uid) $data['date_time'] = $mail->date; - $data['subject'] = $mail->subject; + $data['subject'] = mb_convert_encoding($mail->subject, "UTF-8", "auto"); if(!isset($data['subject']) || $data['subject'] == "") { $data['subject'] = "(no subject)"; } - $data['message_html'] = $mail->textHtml; - $data['message_plain'] = $mail->textPlain; + $data['message_html'] = mb_convert_encoding($mail->textHtml, "UTF-8", "auto"); + $data['message_plain'] = mb_convert_encoding($mail->textPlain, "UTF-8", "auto"); $data['has_attachments'] = null; @@ -311,7 +346,21 @@ function getBcc($mail) } //---------------------------------------------------------- + function markAsRead($uid){ + $this->connect(); + return $this->imap->markMailAsRead($uid); + } + //---------------------------------------------------------- + function markMailAsUnread($uid){ + $this->connect(); + return $this->imap->markMailAsUnread($uid); + } //---------------------------------------------------------- + function getMailAttachments($mail_uid){ + $this->connect(); + $mail = $this->imap->getMail($mail_uid); + return $mail->getAttachments(); + } //---------------------------------------------------------- } diff --git a/Libraries/VaahPayPal.md b/Libraries/VaahPayPal.md new file mode 100644 index 0000000..5242896 --- /dev/null +++ b/Libraries/VaahPayPal.md @@ -0,0 +1,125 @@ +# VaahPayPal +> Small Laravel Helpers + +### Installation + +VaahPaypal provides to you a simple way to integrate Paypal in your Laravel application. + +### Dependencies +- [PayPal-PHP-SDK](https://github.com/paypal/PayPal-PHP-SDK) + +### Installation + +```shell script +composer require paypal/rest-api-sdk-php +``` +### Add env variables: + +`PayPal live` and `PayPal sandbox` are two different environments for using the PayPal API. The live environment is the real PayPal network that processes actual payments, while the sandbox environment is a simulated test environment that allows developers to test their integration with the PayPal API without using real money. +```env +## For PayPal Sandbox +PAYPAL_MODE=sandbox +PAYPAL_SANDBOX_CLIENT_ID=xxxxxxxxxxxxxxx +PAYPAL_SANDBOX_CLIENT_SECRET=xxxxxxxxxxxxx +## For PayPal Live +PAYPAL_MODE=live +PAYPAL_LIVE_CLIENT_ID=xxxxxxxxxxxxxxx +PAYPAL_LIVE_CLIENT_SECRET=xxxxxxxxxxxxx +``` +To obtain your PayPal sandbox client ID and client secret, you will need to complete the following steps: + + 1. Visit the [PayPal Developer](https://developer.paypal.com/home) website and sign in to your account. + 2. Click on the `Sandbox > Accounts` option in the top menu. + 3. In the `Business` section, click on the `Create` button to create a + new sandbox business account. + 4. Enter the required information to create your account and click `Create Account`. + 5. Once your account has been created, click on the `Profile` link next + to the account. + 6. On the next page, you will see your `sandbox client ID` and + `client secret`. Make sure to save these values, as you will need them to + authenticate your app with PayPal in the sandbox environment. + +### Initialize VaahPaypal + ```php +//Initialize the VaahPaypal + $vaahPaypal = new VaahPayPal( + $client_id, + $client_secret, + $return_url, + $cancel_url, + $mode +); +``` +| Name | Description | Required | Default | +|--|--|--|--| +| client_id | PayPal Live/Sandbox client id| Yes +| client_secret| PayPal Live/Sandbox client_secret| Yes +| return_ url| redirect the user to after they have completed a payment.| No | /api/vaah/paypal/execute +| cancel_url | redirect the user to after they have canceled a payment. | No| /api/vaah/paypal/cancel| +| mode | environments for managing payments | No | sandbox + +### Methods +- Paypal Create Order + +|Name| Required | Type | +|--|--|--| +| name | yes | String | +| quantity| yes | String +| amount| yes | String +| description| yes | String +| currency | yes | String | +|shipping | No | Integer +|tax| No | Integer +```php +$vaahPaypal->pay([ + 'name' => 'Name', + 'amount' => 100, + 'currency' => 'USD', + 'description' => 'Description', + 'quantity' => 1, + ]); + ``` + +**Success response** + ```php + [ + 'status' => 'success'; + 'approval_url' = 'approval url'; + 'payment_id' = 'xxxxx'; + 'token' = 'EC-xxxxxxxx'; + ]; + ``` + **Error Response** + ```php + [ + 'status' => 'failed'; + 'errors' = 'errors'; + ]; + ``` + - Execute Order + +|Name| Required +|--|--| +| payment_id | yes | +| payer_id | yes | +```php + $payment_id = 'xxxx'; + $payer_id = 'xxxx'; + $vaahPaypal->executePayment($payment_id, $payer_id); + ``` + +**Success response** +```php + [ + 'status' => 'success'; + 'data' => 'data'; //array + ]; + ``` + **Error response** + ```php + [ + 'status' => 'failed'; + 'errors' = 'errors'; + ]; +``` +Reference url: https://developer.paypal.com/api/rest/ diff --git a/Libraries/VaahPayPal.php b/Libraries/VaahPayPal.php new file mode 100644 index 0000000..31e7f3f --- /dev/null +++ b/Libraries/VaahPayPal.php @@ -0,0 +1,225 @@ +mode = $mode; + $this->client_id = $client_id; + $this->client_secret = $client_secret; + $this->return_url = $return_url; + $this->cancel_url = $cancel_url; + } + + //---------------------------------------------------------- + public function pay($inputs){ + $rules = [ + 'name' => 'required', + 'amount' => 'required', + 'currency' => 'required', + 'description' => 'required', + 'quantity' => 'required', + ]; + $validator = \Validator::make($inputs, $rules); + if ($validator->fails()) { + $errors = $validator->errors(); + $response['status'] = 'failed'; + $response['errors'] = $errors; + return $response; + } + $payer = new \PayPal\Api\Payer(); + $payer->setPaymentMethod("paypal"); + //set item info + $item = new \PayPal\Api\Item(); + $item->setName($inputs['name']) + ->setDescription($inputs['description']) + ->setCurrency($inputs['currency']) + ->setPrice($inputs['amount']) + ->setQuantity($inputs['quantity']); + //set item list + $itemList = new \PayPal\Api\ItemList(); + $itemList->setItems(array($item)); + //details + $details = new \PayPal\Api\Details(); + $shipping = $inputs['shipping'] ?? 0; + $tax = $inputs['tax'] ?? 0; + + $subtotal = ($inputs['amount'] * $inputs['quantity']) + $shipping + $tax; + $details->setShipping($shipping) + ->setTax($tax) + ->setSubtotal($subtotal); + + //set amount + $amount = new \PayPal\Api\Amount(); + $total = $inputs['amount'] * $item->getQuantity(); + $amount->setCurrency($inputs['currency']) + ->setTotal($total) + ->setDetails($details); + + //set transaction + $transaction = new \PayPal\Api\Transaction(); + $transaction->setAmount($amount)->setItemList($itemList) + ->setDescription($inputs['description']) + ->setInvoiceNumber(uniqid()); + //set redirect urls + $redirectUrls = new \PayPal\Api\RedirectUrls(); + $redirectUrls->setReturnUrl($this->return_url) + ->setCancelUrl($this->cancel_url); + //set payment + $payment = new \PayPal\Api\Payment(); + $payment->setIntent("sale") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction)); + + //create payment with valid api context + try { + $resp = $payment->create($this->getApiContext()); + $approvalUrl = $resp->getApprovalLink(); //approval url + $response = []; + $response['status'] = 'success'; + $response['data']['approval_url'] = $approvalUrl; + $response['data']['payment_id'] = $resp->getId(); + $response['data']['token'] = $resp->getToken(); + return $response; + } catch (\PayPal\Exception\PayPalConnectionException $ex) { + $response = []; + $response['status'] = 'failed'; + $response['errors'] = $ex->getData(); + return $response; + } catch (\Exception $ex) { + $response = []; + $response['status'] = 'failed'; + $response['errors'] = $ex->getMessage(); + return $response; + } + } + //---------------------------------------------------------- + public function getUserInfo(){ + //getting user details + try { + $token = $this->getApiContext()->getCredential()->getAccessToken($this->getApiContext()); //get access token + $user = OpenIdUserinfo::getUserinfo(['access_token' => $token], $this->getApiContext()); + $response = []; + $response['status'] = 'success'; + $response['data'] = $user->toArray(); + return $response; + } catch (\PayPal\Exception\PayPalConnectionException $ex) { + $response = []; + $response['status'] = 'failed'; + $response['errors'] = $ex->getData(); + return $response; + } catch (\Exception $ex) { + $response = []; + $response['status'] = 'failed'; + $response['errors'] = $ex->getMessage(); + return $response; + } + } + //---------------------------------------------------------- + public function executePayment($paymentId, $payerId) + { + try { + $payment = \PayPal\Api\Payment::get($paymentId, $this->getApiContext()); + $execution = new \PayPal\Api\PaymentExecution(); + $execution->setPayerId($payerId); + $result = $payment->execute($execution, $this->getApiContext()); + $response = []; + $response['status'] = 'success'; + $response['data'] = $result->toArray(); + return $response; + } catch (\PayPal\Exception\PayPalConnectionException $ex) { + $response = []; + $response['status'] = 'failed'; + $response['errors'] = $ex->getData(); + return $response; + } catch (\Exception $ex) { + $response = []; + $response['status'] = 'failed'; + $response['errors'] = $ex->getMessage(); + return $response; + } + } + //---------------------------------------------------------- + private function getApiContext() { + // #### SDK configuration + // Register the sdk_config.ini file in current directory + // as the configuration source. + /* + if(!defined("PP_CONFIG_PATH")) { + define("PP_CONFIG_PATH", __DIR__); + } + */ + // ### Api context + // Use an ApiContext object to authenticate + // API calls. The clientId and clientSecret for the + // OAuthTokenCredential class can be retrieved from + // developer.paypal.com + $apiContext = new ApiContext( + new OAuthTokenCredential( + $this->client_id, + $this->client_secret + ), + + ); + // Comment this line out and uncomment the PP_CONFIG_PATH + // 'define' block if you want to use static file + // based configuration + $apiContext->setConfig( + array( + 'mode' => $this->mode, + 'log.LogEnabled' => true, + 'log.FileName' => '../PayPal.log', + 'log.LogLevel' => 'DEBUG', + // PLEASE USE `INFO` LEVEL FOR LOGGING IN LIVE ENVIRONMENTS + 'cache.enabled' => true, + //'cache.FileName' => '/PaypalCache' // for determining paypal cache directory + // 'http.CURLOPT_CONNECTTIMEOUT' => 30 + // 'http.headers.PayPal-Partner-Attribution-Id' => '123123123' + //'log.AdapterFactory' => '\PayPal\Log\DefaultLogFactory' // Factory class implementing \PayPal\Log\PayPalLogFactory + ) + ); + // Partner Attribution Id + // Use this header if you are a PayPal partner. Specify a unique BN Code to receive revenue attribution. + // To learn more or to request a BN Code, contact your Partner Manager or visit the PayPal Partner Portal + // $apiContext->addRequestHeader('PayPal-Partner-Attribution-Id', '123123123'); + return $apiContext; + } + //---------------------------------------------------- +} diff --git a/Libraries/VaahStripe.md b/Libraries/VaahStripe.md index feff3c0..15a77de 100644 --- a/Libraries/VaahStripe.md +++ b/Libraries/VaahStripe.md @@ -76,12 +76,100 @@ Reference url: https://stripe.com/docs/api 'state' => 'xxxxxx' // optional ]; - $return_url = ""; // URL to redirect your customer back to after they authenticate or cancel their payment + $return_url = http://localhost/vaahcms/public/ // URL to redirect your customer back to after they authenticate or cancel their payment \VaahStripe::pay($customer, $card, $package, $address, $return_url); ``` +Success Response + +``` +{ + "status": "success", + "data": { + "id": "pi_1LMvsxxxxxxxxxxxxxxxxxx", // Payment Intent ID + "object": "payment_intent", + "allowed_source_types": [ + "card" + ], + "amount": 200, + "amount_capturable": 0, + "amount_details": { + "tip": [] + }, + "amount_received": 0, + "application": null, + "application_fee_amount": null, + "automatic_payment_methods": null, + "canceled_at": null, + "cancellation_reason": null, + "capture_method": "automatic", + "charges": { + "object": "list", + "data": [], + "has_more": false, + "total_count": 0, + "url": "/v1/charges?payment_intent=pi_1LMvsxxxxxxxxxxxxxxxxxx" + }, + "client_secret": "pi_1LMvsxxxxxxxxxxxxxxxxxx_secret_8RZiIyhUEGDqfyLOgSUEAEhXN", + "confirmation_method": "automatic", + "created": 1658158118, + "currency": "usd", + "customer": "cus_M564xxxxxxx", + "description": "testing", + "invoice": null, + "last_payment_error": null, + "livemode": false, + "metadata": [], + "next_action": { + "redirect_to_url": { + "return_url": "http://localhost/vikram/vaahcms-dev-env/public", + "url": "https://hooks.stripe.com/3d_secure_2/hosted?merchant= // Url to complete your 3D secure Payment or open OTP Page + acct_1G43A8GBqaITyEUt&payment_intent=pi_1LMvsxxxxxxxxxxxxxxxxxx& + payment_intent_client_secret=pi_1LMvsxxxxxxxxxxxxxxxxxx_secret_8RZiIyhUEGDqfyLOgSUEAEhXN& + publishable_key=pk_test_xaKKES0OlRzwNj6mCRBbjfc200upEjyqmB&source=src_1LMvsEGBqaITyEUtehquCgzp" + }, + "type": "redirect_to_url" + }, + "next_source_action": { + "type": "authorize_with_url", + "authorize_with_url": { + "return_url": "http://localhost/vikram/vaahcms-dev-env/public", + "url": "https://hooks.stripe.com/3d_secure_2/hosted?merchant= // Url to complete your 3D secure Payment or open OTP Page + acct_1G43A8GBqaITyEUt&payment_intent=pi_1LMvsxxxxxxxxxxxxxxxxxx& + payment_intent_client_secret=pi_1LMvsxxxxxxxxxxxxxxxxxx_secret_8RZiIyhUEGDqfyLOgSUEAEhXN& + publishable_key=pk_test_xaKKES0OlRzwNj6mCRBbjfc200upEjyqmB&source=src_1LMvsEGBqaITyEUtehquCgzp" + } + }, + "on_behalf_of": null, + "payment_method": "pm_1LMvsxxxxxxxxxxxxxxxxxx", + "payment_method_options": { + "card": { + "installments": null, + "mandate_options": null, + "network": null, + "request_three_d_secure": "automatic" + } + }, + "payment_method_types": [ + "card" + ], + "processing": null, + "receipt_email": null, + "review": null, + "setup_future_usage": null, + "shipping": null, + "source": null, + "statement_descriptor": null, + "statement_descriptor_suffix": null, + "status": "requires_source_action", + "transfer_data": null, + "transfer_group": null + } +} +``` + - Stripe Subscription ```php @@ -106,14 +194,103 @@ Reference url: https://stripe.com/docs/api 'state' => 'xxxxxx' // optional ]; - $price_id = 50; // Price define the unit cost, currency, and (optional) billing cycle for Subcription + $price_id You can generate Price ID from createPrice Method of Vaah Stripe // Price define the unit cost, currency, and (optional) billing cycle for Subcription + or You can create directly from Stripe Dashboard by visit https://dashboard.stripe.com/test/products/create - $return_url = ""; // URL to redirect your customer back to after they authenticate or cancel their payment + $return_url = http://localhost/vaahcms/public/ // URL to redirect your customer back to after they authenticate or cancel their payment \VaahStripe::subscription($customer, $card, $address, $price_id, $return_url); ``` +Success Response + +``` +{ + "status": "success", + "data": { + "id": "pi_1LMwxxxxxxxxxxxxxxxxxxxx", // Payment Intent ID + "object": "payment_intent", + "allowed_source_types": [ + "card" + ], + "amount": 79900, + "amount_capturable": 0, + "amount_details": { + "tip": [] + }, + "amount_received": 0, + "application": null, + "application_fee_amount": null, + "automatic_payment_methods": null, + "canceled_at": null, + "cancellation_reason": null, + "capture_method": "automatic", + "charges": { + "object": "list", + "data": [], + "has_more": false, + "total_count": 0, + "url": "/v1/charges?payment_intent=pi_1LMwxxxxxxxxxxxxxxxxxxxx" + }, + "client_secret": "pi_1LMwxxxxxxxxxxxxxxxxxxxx_secret_usv8FrEvzU0CuWEyRjmUKlmjD", + "confirmation_method": "automatic", + "created": 1658161603, + "currency": "usd", + "customer": "cus_M570qAPnoC6xl1", + "description": "Subscription creation", + "invoice": "in_1LMwmxxxxxxxxxxxxxxxxxxx", + "last_payment_error": null, + "livemode": false, + "metadata": [], + "next_action": { + "redirect_to_url": { + "return_url": "http://localhost/vikram/vaahcms-dev-env/public", + "url": "https://hooks.stripe.com/3d_secure_2/hosted?merchant= // Url to complete your 3D secure Payment or open OTP Page + acct_1G43A8GBqaITyEUt&payment_intent=pi_1LMwxxxxxxxxxxxxxxxxxxxx& + payment_intent_client_secret=pi_1LMwxxxxxxxxxxxxxxxxxxxx_secret_usv8FrEvzU0CuWEyRjmUKlmjD& + publishable_key=pk_test_xaKKES0OlRzwNj6mCRBbjfc200upEjyqmB&source=src_1LMwmQGBqaITyEUtQsNKeDZn" + }, + "type": "redirect_to_url" + }, + "next_source_action": { + "type": "authorize_with_url", + "authorize_with_url": { + "return_url": "http://localhost/vikram/vaahcms-dev-env/public", + "url": "https://hooks.stripe.com/3d_secure_2/hosted?merchant= // Url to complete your 3D secure Payment or open OTP Page + acct_1G43A8GBqaITyEUt&payment_intent=pi_1LMwxxxxxxxxxxxxxxxxxxxx& + payment_intent_client_secret=pi_1LMwxxxxxxxxxxxxxxxxxxxx_secret_usv8FrEvzU0CuWEyRjmUKlmjD& + publishable_key=pk_test_xaKKES0OlRzwNj6mCRBbjfc200upEjyqmB&source=src_1LMwmQGBqaITyEUtQsNKeDZn" + } + }, + "on_behalf_of": null, + "payment_method": null, + "payment_method_options": { + "card": { + "installments": null, + "mandate_options": null, + "network": null, + "request_three_d_secure": "automatic" + } + }, + "payment_method_types": [ + "card" + ], + "processing": null, + "receipt_email": null, + "review": null, + "setup_future_usage": "off_session", + "shipping": null, + "source": "card_1LMxxxxxxxxxxxxxxxxx", + "statement_descriptor": null, + "statement_descriptor_suffix": null, + "status": "requires_source_action", + "transfer_data": null, + "transfer_group": null + } +} +``` + - Create Product ```php @@ -126,14 +303,54 @@ Reference url: https://stripe.com/docs/api ``` +Success Response + +``` +{ + "status": "success", + "data": { + "id": "prod_M57xxxxxxxxxxx", // Product Id + "object": "product", + "active": true, + "attributes": [], + "created": 1658162168, + "default_price": null, + "description": "Testing Product", + "images": [], + "livemode": false, + "metadata": [], + "name": "Vikram", + "package_dimensions": null, + "shippable": null, + "skus": { + "object": "list", + "data": [], + "has_more": false, + "total_count": 0, + "url": "/v1/skus?product=prod_M57xxxxxxxxxxx&active=true" + }, + "statement_descriptor": null, + "tax_code": null, + "type": "service", + "unit_label": null, + "updated": 1658162168, + "url": null + } +} +``` + - Create Price ```php - $request = [ + // You need to have Product id to create Price. + + $request => [ 'product_id' => 'xxxxxx', 'currency' => 'usd', 'amount' => '01', - 'interval' => '01' + 'recurring' => [ + 'interval' => 'month' // month, year, week, or day + ] ]; @@ -141,17 +358,92 @@ Reference url: https://stripe.com/docs/api ``` +Success Response + +``` +{ + "status": "success", + "data": { + "id": "price_1LMxxxxxxxxxxxxxxxx", // Price id + "object": "price", + "active": true, + "billing_scheme": "per_unit", + "created": 1658162583, + "currency": "usd", + "custom_unit_amount": null, + "livemode": false, + "lookup_key": null, + "metadata": [], + "nickname": null, + "product": "prod_M579xxxxxxxx", // Product id + "recurring": { + "aggregate_usage": null, + "interval": "month", + "interval_count": 1, + "trial_period_days": null, + "usage_type": "licensed" + }, + "tax_behavior": "unspecified", + "tiers_mode": null, + "transform_quantity": null, + "type": "recurring", + "unit_amount": 20, + "unit_amount_decimal": "20" + } +} +``` + - Find Product ```php + + $name // Product Name \VaahStripe::findProductByName($name); ``` +Success Response + +``` +{ + "status": "success", + "data": { + "id": "prod_K1xxxxxxxx", + "object": "product", + "active": true, + "attributes": [], + "caption": null, + "created": 1628777285, + "deactivate_on": [], + "default_price": null, + "description": "WP-Maintenance-Premium-Monthly", + "images": [], + "livemode": false, + "metadata": [], + "name": "WP-Maintenance-Standard-Monthly", + "package_dimensions": null, + "shippable": true, + "skus": { + "object": "list", + "data": [], + "has_more": false, + "total_count": 0, + "url": "/v1/skus?product=prod_K1xxxxxxxxx&active=true" + }, + "tax_code": null, + "type": "good", + "updated": 1628777285, + "url": null + } +} +``` + - Find Price ```php - $product_id = 1; + // You need to have Product id to create Price. + + $product_id $value = ""; //optional @@ -160,3 +452,38 @@ Reference url: https://stripe.com/docs/api \VaahStripe::getProductPrice($product_id, $value, $by); ``` + +Success Response + +``` +{ + "status": "success", + "data": { + "id": "price_1LMx2xxxxxxxxxxxxxxx", + "object": "price", + "active": true, + "billing_scheme": "per_unit", + "created": 1658162583, + "currency": "usd", + "custom_unit_amount": null, + "livemode": false, + "lookup_key": null, + "metadata": [], + "nickname": null, + "product": "prod_M57xxxxxxxxxxxx", + "recurring": { + "aggregate_usage": null, + "interval": "month", + "interval_count": 1, + "trial_period_days": null, + "usage_type": "licensed" + }, + "tax_behavior": "unspecified", + "tiers_mode": null, + "transform_quantity": null, + "type": "recurring", + "unit_amount": 20, + "unit_amount_decimal": "20" + } +} +``` diff --git a/composer.json b/composer.json index 77f14b8..00ab58c 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "webreinvent/vaahextend", "description": "Quickly adaptable helpers to extend VaahCMS", "keywords": ["vaahcms", "laravel"], - "version": "0.0.5", + "version": "1.0.1", "homepage": "https://www.webreinvent.com", "license": "MIT", "authors": [