Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cb2f6a9
fix: temporarily revert back to old code examples for advanced (#78)
gregjopa Aug 31, 2023
fa12c9c
Update README with codespace details (#80)
sdarshale Sep 18, 2023
e26deb2
chore(docs): update readme feedback header section (#81)
sdarshale Sep 22, 2023
53f4e72
Update README.md for typo fix (#83)
cnallam Oct 2, 2023
d3c1ada
Rename the advanced integration "new" folder to "v1" (#85)
gregjopa Oct 4, 2023
5c89c3c
Add new card fields beta component (#84)
gregjopa Oct 5, 2023
ba6914a
Fix codespaces path
gregjopa Oct 5, 2023
f62771f
Use existing css to center beta card form
gregjopa Oct 6, 2023
5a3ea22
fix(docs): update instructions for replacing client-id in html (#86)
gregjopa Oct 6, 2023
f240e26
Add codespaces example for hosted fields v1 changes
gregjopa Oct 9, 2023
7c03b1a
Update the name of the v2 card fields codespaces config (#88)
gregjopa Oct 19, 2023
4fe6e5a
My Changes
cnallam Oct 24, 2023
39aeb3c
update advanced integration format to support v1 and v2 (#87)
devapplepaypal Oct 24, 2023
8895d07
Update codespaces links to support v1 and v2 (#89)
gregjopa Oct 24, 2023
91683d3
Clean up advanced-integration directory (#90)
gregjopa Oct 24, 2023
e453180
Fix codespace path for advanced integration v2 (#92)
gregjopa Oct 25, 2023
c4ee30f
Add ejs to better match the v2 advanced integration docs (#93)
gregjopa Oct 25, 2023
4603a51
Update instructions for v2 card fields (#97)
gregjopa Oct 26, 2023
4f82e50
feat: add example for saving a payment method (#99)
jshawl Nov 13, 2023
31e5b51
Update devcontainer.json with paypal vs code extension (#106)
NavinPayPal Dec 13, 2023
6419cb9
Update hosted-fields example to new standards (#109)
gregjopa Dec 20, 2023
ecc5ab5
Adding changes for devcontainer file for save payment method
NavinPayPal Jan 10, 2024
e385dc5
Updating Readme file to add Codespaces button
NavinPayPal Jan 11, 2024
a354698
Updating the devcontainer file
NavinPayPal Jan 16, 2024
a2074e9
Updating devcontainer file for save payment
NavinPayPal Jan 17, 2024
dd359b8
Merge pull request #115 from NavinPayPal/main
NavinPayPal Feb 20, 2024
633fe7e
fix one click payment popup issue (#126)
jshawl Apr 11, 2024
bd8f509
fix lint failure (#129)
jshawl Apr 12, 2024
a70265b
feat: update Card Fields integration with Billing Address (#131)
mchoun Jun 3, 2024
f61c97a
Add multiple language support for Standard & Advanced Integration (#152)
amsourav Sep 17, 2024
bb12328
Add client and server language selection while launching code spaces …
rekhaabaidipati Oct 1, 2024
4f9852f
feat: add support for php and java server sdk (#158)
amsourav Oct 10, 2024
faf8b4d
Fix client worrkspace foldere clone (#162)
rekhaabaidipati Oct 15, 2024
2cdd5d3
feat: migrate to dotnet server sdk (#163)
amsourav Oct 16, 2024
843672d
update Python Flask/Ruby Sinatra examples (#160)
LeonarthusMectus Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update Python Flask/Ruby Sinatra examples (#160)
  • Loading branch information
LeonarthusMectus authored Oct 16, 2024
commit 843672dfc74581b770dc7b3fc369d9cbf7545656
1 change: 1 addition & 0 deletions advanced-integration/v2/server/python/.flaskenv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FLASK_RUN_PORT=8080
41 changes: 41 additions & 0 deletions advanced-integration/v2/server/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Standard Integration Python Flask Sample

PayPal Standard Integration sample in Python using Flask

## Running the sample

1. **Setup a virtual environment**

```sh
python3 -m venv .venv
```

1. **Install the dependencies**

```sh
pip install -r requirements.txt
```

1. **Add your API credentials to the environment:**

- **Windows**

```powershell
$env:PAYPAL_CLIENT_ID = "<PAYPAL_CLIENT_ID>"
$env:PAYPAL_CLIENT_SECRET = "<PAYPAL_CLIENT_SECRET>"
```

- **Unix**

```bash
export PAYPAL_CLIENT_ID="<PAYPAL_CLIENT_ID>"
export PAYPAL_CLIENT_SECRET="<PAYPAL_CLIENT_SECRET>"
```

1. **Run the server**

```sh
flask --app server run
```

1. Go to [http://localhost:8080/](http://localhost:8080/)
2 changes: 2 additions & 0 deletions advanced-integration/v2/server/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==3.0.3
paypal-server-sdk==0.5.2
86 changes: 86 additions & 0 deletions advanced-integration/v2/server/python/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import logging
import os

from flask import Flask, request
from paypalserversdk.http.auth.o_auth_2 import ClientCredentialsAuthCredentials
from paypalserversdk.logging.configuration.api_logging_configuration import LoggingConfiguration, \
RequestLoggingConfiguration, ResponseLoggingConfiguration
from paypalserversdk.paypalserversdk_client import PaypalserversdkClient
from paypalserversdk.controllers.orders_controller import OrdersController
from paypalserversdk.models.amount_with_breakdown import AmountWithBreakdown
from paypalserversdk.models.checkout_payment_intent import CheckoutPaymentIntent
from paypalserversdk.models.order_request import OrderRequest
from paypalserversdk.models.purchase_unit_request import PurchaseUnitRequest
from paypalserversdk.api_helper import ApiHelper

app = Flask(__name__)

paypal_client: PaypalserversdkClient = PaypalserversdkClient(
client_credentials_auth_credentials=ClientCredentialsAuthCredentials(
o_auth_client_id=os.getenv('PAYPAL_CLIENT_ID'),
o_auth_client_secret=os.getenv('PAYPAL_CLIENT_SECRET')
),
logging_configuration=LoggingConfiguration(
log_level=logging.INFO,
# Disable masking of sensitive headers for Sandbox testing.
# This should be set to True (the default if unset)in production.
mask_sensitive_headers=False,
request_logging_config=RequestLoggingConfiguration(
log_headers=True,
log_body=True
),
response_logging_config=ResponseLoggingConfiguration(
log_headers=True,
log_body=True
)
)
)

'''
Health check
'''
@app.route('/', methods=['GET'])
def index():
return {"message": "Server is running"}

orders_controller: OrdersController = paypal_client.orders

'''
Create an order to start the transaction.

@see https://developer.paypal.com/docs/api/orders/v2/#orders_create
'''
@app.route('/api/orders', methods=['POST'])
def create_order():
request_body = request.get_json()
# use the cart information passed from the front-end to calculate the order amount detals
cart = request_body['cart']
order = orders_controller.orders_create({
"body": OrderRequest(
intent=CheckoutPaymentIntent.CAPTURE,
purchase_units=[
PurchaseUnitRequest(
AmountWithBreakdown(
currency_code='USD',
value='100.00'
)
)
]
),
"prefer": 'return=representation'
}
)
return ApiHelper.json_serialize(order.body)

'''
Capture payment for the created order to complete the transaction.

@see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
'''
@app.route('/api/orders/<order_id>/capture', methods=['POST'])
def capture_order(order_id):
order = orders_controller.orders_capture({
'id': order_id,
'prefer': 'return=representation'
})
return ApiHelper.json_serialize(order.body)
1 change: 1 addition & 0 deletions advanced-integration/v2/server/ruby/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.5
9 changes: 9 additions & 0 deletions advanced-integration/v2/server/ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "paypal-server-sdk", "~> 0.5.2"
gem "puma", "~> 6.4"
gem "rackup", "~> 2.1"
gem "sinatra", "~> 4.0"
gem "sinatra-contrib", "~> 4.0"
37 changes: 37 additions & 0 deletions advanced-integration/v2/server/ruby/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Standard Integration Ruby Sinatra Sample

PayPal Standard Integration sample in Ruby using Sinatra

## Running the sample

1. **Ensure you have a supported Ruby version installed**: [Ruby Maintenance Branches](https://www.ruby-lang.org/en/downloads/branches/)

1. **Install the dependencies**

```bash
bundle install
```

1. **Add your API credentials to the environment:**

- **Windows**

```powershell
$env:PAYPAL_CLIENT_ID = "<PAYPAL_CLIENT_ID>"
$env:PAYPAL_CLIENT_SECRET = "<PAYPAL_CLIENT_SECRET>"
```

- **Unix**

```bash
export PAYPAL_CLIENT_ID="<PAYPAL_CLIENT_ID>"
export PAYPAL_CLIENT_SECRET="<PAYPAL_CLIENT_SECRET>"
```

1. **Run the server**

```bash
bundle exec ruby server.rb
```

1. Go to [http://localhost:8080/](http://localhost:8080/)
67 changes: 67 additions & 0 deletions advanced-integration/v2/server/ruby/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'paypal_server_sdk'
require 'sinatra'
require 'sinatra/json'

include PaypalServerSdk

set :port, 8080

paypal_client = PaypalServerSdk::Client.new(
client_credentials_auth_credentials: ClientCredentialsAuthCredentials.new(
o_auth_client_id: ENV['PAYPAL_CLIENT_ID'],
o_auth_client_secret: ENV['PAYPAL_CLIENT_SECRET']
),
environment: Environment::SANDBOX,
logging_configuration: LoggingConfiguration.new(
mask_sensitive_headers: false,
log_level: Logger::INFO,
request_logging_config: RequestLoggingConfiguration.new(
log_headers: true,
log_body: true,
),
response_logging_config: ResponseLoggingConfiguration.new(
log_headers: true,
log_body: true
)
)
)

# Health Check
get '/' do
json :message => "Server is running"
end

# Create an order to start the transaction.
#
# @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
post "/api/orders" do
# use the cart information passed from the front-end to calculate the order amount detals
cart = JSON.parse request.body.read
order_response = paypal_client.orders.orders_create({
'body' => OrderRequest.new(
intent: CheckoutPaymentIntent::CAPTURE,
purchase_units: [
PurchaseUnitRequest.new(
amount: AmountWithBreakdown.new(
currency_code: 'USD',
value: '100.00'
)
)
]
),
'prefer' => 'return=representation'
})
json order_response.data
end

# Capture payment for the created order to complete the transaction.
#
# @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
post '/api/orders/:order_id/capture' do |order_id|
capture_response = paypal_client.orders.orders_capture({
'id' => order_id,
'prefer' => 'return=representation'
})
json capture_response.data
rescue ErrorException => e
end
1 change: 1 addition & 0 deletions standard-integration/server/python/.flaskenv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FLASK_RUN_PORT=8080
41 changes: 41 additions & 0 deletions standard-integration/server/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Standard Integration Python Flask Sample

PayPal Standard Integration sample in Python using Flask

## Running the sample

1. **Setup a virtual environment**

```sh
python3 -m venv .venv
```

1. **Install the dependencies**

```sh
pip install -r requirements.txt
```

1. **Add your API credentials to the environment:**

- **Windows**

```powershell
$env:PAYPAL_CLIENT_ID = "<PAYPAL_CLIENT_ID>"
$env:PAYPAL_CLIENT_SECRET = "<PAYPAL_CLIENT_SECRET>"
```

- **Unix**

```bash
export PAYPAL_CLIENT_ID="<PAYPAL_CLIENT_ID>"
export PAYPAL_CLIENT_SECRET="<PAYPAL_CLIENT_SECRET>"
```

1. **Run the server**

```sh
flask --app server run
```

1. Go to [http://localhost:8080/](http://localhost:8080/)
2 changes: 2 additions & 0 deletions standard-integration/server/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==3.0.3
paypal-server-sdk==0.5.2
86 changes: 86 additions & 0 deletions standard-integration/server/python/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import logging
import os

from flask import Flask, request
from paypalserversdk.http.auth.o_auth_2 import ClientCredentialsAuthCredentials
from paypalserversdk.logging.configuration.api_logging_configuration import LoggingConfiguration, \
RequestLoggingConfiguration, ResponseLoggingConfiguration
from paypalserversdk.paypalserversdk_client import PaypalserversdkClient
from paypalserversdk.controllers.orders_controller import OrdersController
from paypalserversdk.models.amount_with_breakdown import AmountWithBreakdown
from paypalserversdk.models.checkout_payment_intent import CheckoutPaymentIntent
from paypalserversdk.models.order_request import OrderRequest
from paypalserversdk.models.purchase_unit_request import PurchaseUnitRequest
from paypalserversdk.api_helper import ApiHelper

app = Flask(__name__)

paypal_client: PaypalserversdkClient = PaypalserversdkClient(
client_credentials_auth_credentials=ClientCredentialsAuthCredentials(
o_auth_client_id=os.getenv('PAYPAL_CLIENT_ID'),
o_auth_client_secret=os.getenv('PAYPAL_CLIENT_SECRET')
),
logging_configuration=LoggingConfiguration(
log_level=logging.INFO,
# Disable masking of sensitive headers for Sandbox testing.
# This should be set to True (the default if unset)in production.
mask_sensitive_headers=False,
request_logging_config=RequestLoggingConfiguration(
log_headers=True,
log_body=True
),
response_logging_config=ResponseLoggingConfiguration(
log_headers=True,
log_body=True
)
)
)

'''
Health check
'''
@app.route('/', methods=['GET'])
def index():
return {"message": "Server is running"}

orders_controller: OrdersController = paypal_client.orders

'''
Create an order to start the transaction.

@see https://developer.paypal.com/docs/api/orders/v2/#orders_create
'''
@app.route('/api/orders', methods=['POST'])
def create_order():
request_body = request.get_json()
# use the cart information passed from the front-end to calculate the order amount detals
cart = request_body['cart']
order = orders_controller.orders_create({
"body": OrderRequest(
intent=CheckoutPaymentIntent.CAPTURE,
purchase_units=[
PurchaseUnitRequest(
AmountWithBreakdown(
currency_code='USD',
value='100.00'
)
)
]
),
"prefer": 'return=representation'
}
)
return ApiHelper.json_serialize(order.body)

'''
Capture payment for the created order to complete the transaction.

@see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
'''
@app.route('/api/orders/<order_id>/capture', methods=['POST'])
def capture_order(order_id):
order = orders_controller.orders_capture({
'id': order_id,
'prefer': 'return=representation'
})
return ApiHelper.json_serialize(order.body)
1 change: 1 addition & 0 deletions standard-integration/server/ruby/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.5
Loading