@zimezone/z-command 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/README.md +13 -1
  2. package/dist/commands/init.d.ts.map +1 -1
  3. package/dist/commands/init.js +34 -9
  4. package/dist/commands/init.js.map +1 -1
  5. package/package.json +8 -3
  6. package/templates.zip +0 -0
  7. package/templates/agents/accessibility-expert.agent.md +0 -56
  8. package/templates/agents/ai-engineer.agent.md +0 -61
  9. package/templates/agents/angular-architect.agent.md +0 -49
  10. package/templates/agents/api-designer.agent.md +0 -40
  11. package/templates/agents/api-documenter.agent.md +0 -161
  12. package/templates/agents/architect-review.agent.md +0 -146
  13. package/templates/agents/arm-cortex-expert.agent.md +0 -288
  14. package/templates/agents/azure-infra-engineer.agent.md +0 -57
  15. package/templates/agents/backend-architect.agent.md +0 -309
  16. package/templates/agents/backend-developer.agent.md +0 -61
  17. package/templates/agents/backend-security-coder.agent.md +0 -152
  18. package/templates/agents/bash-pro.agent.md +0 -285
  19. package/templates/agents/blockchain-developer.agent.md +0 -57
  20. package/templates/agents/build-engineer.agent.md +0 -56
  21. package/templates/agents/business-analyst.agent.md +0 -47
  22. package/templates/agents/c-pro.agent.md +0 -35
  23. package/templates/agents/c4-code.agent.md +0 -320
  24. package/templates/agents/c4-component.agent.md +0 -227
  25. package/templates/agents/c4-container.agent.md +0 -248
  26. package/templates/agents/c4-context.agent.md +0 -235
  27. package/templates/agents/cli-developer.agent.md +0 -57
  28. package/templates/agents/cloud-architect.agent.md +0 -56
  29. package/templates/agents/code-architect.agent.md +0 -63
  30. package/templates/agents/code-reviewer.agent.md +0 -49
  31. package/templates/agents/competitive-analyst.agent.md +0 -48
  32. package/templates/agents/conductor-validator.agent.md +0 -245
  33. package/templates/agents/context-manager.agent.md +0 -55
  34. package/templates/agents/cpp-pro.agent.md +0 -59
  35. package/templates/agents/csharp-developer.agent.md +0 -57
  36. package/templates/agents/csharp-pro.agent.md +0 -38
  37. package/templates/agents/customer-support.agent.md +0 -148
  38. package/templates/agents/data-engineer.agent.md +0 -55
  39. package/templates/agents/data-researcher.agent.md +0 -55
  40. package/templates/agents/data-scientist.agent.md +0 -56
  41. package/templates/agents/database-admin.agent.md +0 -142
  42. package/templates/agents/database-administrator.agent.md +0 -50
  43. package/templates/agents/database-architect.agent.md +0 -238
  44. package/templates/agents/database-optimizer.agent.md +0 -144
  45. package/templates/agents/debugger.agent.md +0 -30
  46. package/templates/agents/deployment-engineer.agent.md +0 -0
  47. package/templates/agents/devops-engineer.agent.md +0 -59
  48. package/templates/agents/devops-troubleshooter.agent.md +0 -138
  49. package/templates/agents/django-developer.agent.md +0 -50
  50. package/templates/agents/django-pro.agent.md +0 -159
  51. package/templates/agents/docs-architect.agent.md +0 -77
  52. package/templates/agents/documentation-engineer.agent.md +0 -57
  53. package/templates/agents/dotnet-architect.agent.md +0 -175
  54. package/templates/agents/dx-optimizer.agent.md +0 -63
  55. package/templates/agents/electron-pro.agent.md +0 -56
  56. package/templates/agents/elixir-pro.agent.md +0 -38
  57. package/templates/agents/embedded-systems.agent.md +0 -55
  58. package/templates/agents/error-detective.agent.md +0 -32
  59. package/templates/agents/event-sourcing-architect.agent.md +0 -42
  60. package/templates/agents/fastapi-pro.agent.md +0 -171
  61. package/templates/agents/fintech-engineer.agent.md +0 -57
  62. package/templates/agents/firmware-analyst.agent.md +0 -330
  63. package/templates/agents/flutter-expert.agent.md +0 -50
  64. package/templates/agents/frontend-developer.agent.md +0 -59
  65. package/templates/agents/frontend-security-coder.agent.md +0 -149
  66. package/templates/agents/fullstack-developer.agent.md +0 -46
  67. package/templates/agents/git-workflow-manager.agent.md +0 -57
  68. package/templates/agents/golang-pro.agent.md +0 -50
  69. package/templates/agents/graphql-architect.agent.md +0 -48
  70. package/templates/agents/haskell-pro.agent.md +0 -37
  71. package/templates/agents/hr-pro.agent.md +0 -105
  72. package/templates/agents/incident-responder.agent.md +0 -190
  73. package/templates/agents/ios-developer.agent.md +0 -198
  74. package/templates/agents/iot-engineer.agent.md +0 -56
  75. package/templates/agents/java-architect.agent.md +0 -48
  76. package/templates/agents/java-pro.agent.md +0 -156
  77. package/templates/agents/javascript-pro.agent.md +0 -35
  78. package/templates/agents/julia-pro.agent.md +0 -187
  79. package/templates/agents/kotlin-specialist.agent.md +0 -50
  80. package/templates/agents/laravel-specialist.agent.md +0 -50
  81. package/templates/agents/legacy-modernizer.agent.md +0 -56
  82. package/templates/agents/legal-advisor.agent.md +0 -49
  83. package/templates/agents/llm-architect.agent.md +0 -58
  84. package/templates/agents/malware-analyst.agent.md +0 -272
  85. package/templates/agents/mcp-developer.agent.md +0 -54
  86. package/templates/agents/mermaid-expert.agent.md +0 -39
  87. package/templates/agents/microservices-architect.agent.md +0 -47
  88. package/templates/agents/minecraft-bukkit-pro.agent.md +0 -104
  89. package/templates/agents/ml-engineer.agent.md +0 -56
  90. package/templates/agents/mlops-engineer.agent.md +0 -56
  91. package/templates/agents/mobile-developer.agent.md +0 -45
  92. package/templates/agents/mobile-security-coder.agent.md +0 -163
  93. package/templates/agents/monorepo-architect.agent.md +0 -44
  94. package/templates/agents/multi-agent-coordinator.agent.md +0 -55
  95. package/templates/agents/network-engineer.agent.md +0 -57
  96. package/templates/agents/nextjs-developer.agent.md +0 -48
  97. package/templates/agents/nlp-engineer.agent.md +0 -58
  98. package/templates/agents/observability-engineer.agent.md +0 -228
  99. package/templates/agents/payment-integration.agent.md +0 -56
  100. package/templates/agents/performance-engineer.agent.md +0 -167
  101. package/templates/agents/performance-optimizer.agent.md +0 -57
  102. package/templates/agents/php-pro.agent.md +0 -43
  103. package/templates/agents/platform-engineer.agent.md +0 -57
  104. package/templates/agents/posix-shell-pro.agent.md +0 -284
  105. package/templates/agents/postgres-pro.agent.md +0 -58
  106. package/templates/agents/product-manager.agent.md +0 -55
  107. package/templates/agents/project-manager.agent.md +0 -57
  108. package/templates/agents/prompt-engineer.agent.md +0 -58
  109. package/templates/agents/python-pro.agent.md +0 -48
  110. package/templates/agents/quant-analyst.agent.md +0 -32
  111. package/templates/agents/rails-expert.agent.md +0 -50
  112. package/templates/agents/react-specialist.agent.md +0 -49
  113. package/templates/agents/refactoring-specialist.agent.md +0 -56
  114. package/templates/agents/reference-builder.agent.md +0 -167
  115. package/templates/agents/research-analyst.agent.md +0 -63
  116. package/templates/agents/reverse-engineer.agent.md +0 -202
  117. package/templates/agents/risk-manager.agent.md +0 -41
  118. package/templates/agents/ruby-pro.agent.md +0 -35
  119. package/templates/agents/rust-pro.agent.md +0 -156
  120. package/templates/agents/sales-automator.agent.md +0 -35
  121. package/templates/agents/scala-pro.agent.md +0 -60
  122. package/templates/agents/scrum-master.agent.md +0 -54
  123. package/templates/agents/search-specialist.agent.md +0 -59
  124. package/templates/agents/security-analyst.agent.md +0 -57
  125. package/templates/agents/security-auditor.agent.md +0 -138
  126. package/templates/agents/security-engineer.agent.md +0 -57
  127. package/templates/agents/seo-authority-builder.agent.md +0 -116
  128. package/templates/agents/seo-cannibalization-detector.agent.md +0 -103
  129. package/templates/agents/seo-content-auditor.agent.md +0 -63
  130. package/templates/agents/seo-content-planner.agent.md +0 -88
  131. package/templates/agents/seo-content-refresher.agent.md +0 -98
  132. package/templates/agents/seo-content-writer.agent.md +0 -76
  133. package/templates/agents/seo-keyword-strategist.agent.md +0 -75
  134. package/templates/agents/seo-meta-optimizer.agent.md +0 -72
  135. package/templates/agents/seo-snippet-hunter.agent.md +0 -94
  136. package/templates/agents/seo-specialist.agent.md +0 -57
  137. package/templates/agents/seo-structure-architect.agent.md +0 -88
  138. package/templates/agents/service-mesh-expert.agent.md +0 -41
  139. package/templates/agents/sql-pro.agent.md +0 -146
  140. package/templates/agents/sre-engineer.agent.md +0 -58
  141. package/templates/agents/swift-expert.agent.md +0 -49
  142. package/templates/agents/task-distributor.agent.md +0 -47
  143. package/templates/agents/tdd-orchestrator.agent.md +0 -183
  144. package/templates/agents/technical-writer.agent.md +0 -48
  145. package/templates/agents/temporal-python-pro.agent.md +0 -349
  146. package/templates/agents/terraform-engineer.agent.md +0 -57
  147. package/templates/agents/terraform-specialist.agent.md +0 -137
  148. package/templates/agents/test-automator.agent.md +0 -203
  149. package/templates/agents/test-engineer.agent.md +0 -55
  150. package/templates/agents/threat-modeling-expert.agent.md +0 -44
  151. package/templates/agents/trend-analyst.agent.md +0 -47
  152. package/templates/agents/tutorial-engineer.agent.md +0 -118
  153. package/templates/agents/typescript-pro.agent.md +0 -48
  154. package/templates/agents/ui-designer.agent.md +0 -48
  155. package/templates/agents/ui-ux-designer.agent.md +0 -188
  156. package/templates/agents/ui-visual-validator.agent.md +0 -192
  157. package/templates/agents/ux-researcher.agent.md +0 -48
  158. package/templates/agents/vector-database-engineer.agent.md +0 -43
  159. package/templates/agents/vue-expert.agent.md +0 -48
  160. package/templates/agents/websocket-engineer.agent.md +0 -49
  161. package/templates/agents/workflow-orchestrator.agent.md +0 -48
  162. package/templates/skills/angular-migration/SKILL.md +0 -410
  163. package/templates/skills/api-design-principles/SKILL.md +0 -528
  164. package/templates/skills/api-design-principles/assets/api-design-checklist.md +0 -155
  165. package/templates/skills/api-design-principles/assets/rest-api-template.py +0 -182
  166. package/templates/skills/api-design-principles/references/graphql-schema-design.md +0 -583
  167. package/templates/skills/api-design-principles/references/rest-best-practices.md +0 -408
  168. package/templates/skills/architecture-decision-records/SKILL.md +0 -428
  169. package/templates/skills/architecture-patterns/SKILL.md +0 -494
  170. package/templates/skills/async-python-patterns/SKILL.md +0 -694
  171. package/templates/skills/auth-implementation-patterns/SKILL.md +0 -634
  172. package/templates/skills/changelog-automation/SKILL.md +0 -552
  173. package/templates/skills/code-review/SKILL.md +0 -62
  174. package/templates/skills/code-review-excellence/SKILL.md +0 -520
  175. package/templates/skills/competitive-landscape/SKILL.md +0 -479
  176. package/templates/skills/context-driven-development/SKILL.md +0 -385
  177. package/templates/skills/cost-optimization/SKILL.md +0 -274
  178. package/templates/skills/cqrs-implementation/SKILL.md +0 -554
  179. package/templates/skills/data-quality-frameworks/SKILL.md +0 -587
  180. package/templates/skills/data-storytelling/SKILL.md +0 -453
  181. package/templates/skills/database-migration/SKILL.md +0 -424
  182. package/templates/skills/dbt-transformation-patterns/SKILL.md +0 -561
  183. package/templates/skills/debugging-strategies/SKILL.md +0 -527
  184. package/templates/skills/defi-protocol-templates/SKILL.md +0 -454
  185. package/templates/skills/dependency-upgrade/SKILL.md +0 -409
  186. package/templates/skills/deployment-pipeline-design/SKILL.md +0 -359
  187. package/templates/skills/distributed-tracing/SKILL.md +0 -438
  188. package/templates/skills/dotnet-backend-patterns/SKILL.md +0 -815
  189. package/templates/skills/dotnet-backend-patterns/assets/repository-template.cs +0 -523
  190. package/templates/skills/dotnet-backend-patterns/assets/service-template.cs +0 -336
  191. package/templates/skills/dotnet-backend-patterns/references/dapper-patterns.md +0 -544
  192. package/templates/skills/dotnet-backend-patterns/references/ef-core-best-practices.md +0 -355
  193. package/templates/skills/e2e-testing-patterns/SKILL.md +0 -547
  194. package/templates/skills/employment-contract-templates/SKILL.md +0 -507
  195. package/templates/skills/error-handling-patterns/SKILL.md +0 -636
  196. package/templates/skills/event-store-design/SKILL.md +0 -437
  197. package/templates/skills/fastapi-templates/SKILL.md +0 -567
  198. package/templates/skills/git-advanced-workflows/SKILL.md +0 -400
  199. package/templates/skills/github-actions-templates/SKILL.md +0 -333
  200. package/templates/skills/go-concurrency-patterns/SKILL.md +0 -655
  201. package/templates/skills/grafana-dashboards/SKILL.md +0 -369
  202. package/templates/skills/helm-chart-scaffolding/SKILL.md +0 -544
  203. package/templates/skills/helm-chart-scaffolding/assets/Chart.yaml.template +0 -42
  204. package/templates/skills/helm-chart-scaffolding/assets/values.yaml.template +0 -185
  205. package/templates/skills/helm-chart-scaffolding/references/chart-structure.md +0 -500
  206. package/templates/skills/helm-chart-scaffolding/scripts/validate-chart.sh +0 -244
  207. package/templates/skills/javascript-testing-patterns/SKILL.md +0 -1025
  208. package/templates/skills/langchain-architecture/SKILL.md +0 -338
  209. package/templates/skills/llm-evaluation/SKILL.md +0 -471
  210. package/templates/skills/microservices-patterns/SKILL.md +0 -595
  211. package/templates/skills/modern-javascript-patterns/SKILL.md +0 -911
  212. package/templates/skills/monorepo-management/SKILL.md +0 -622
  213. package/templates/skills/nextjs-app-router-patterns/SKILL.md +0 -544
  214. package/templates/skills/nodejs-backend-patterns/SKILL.md +0 -1020
  215. package/templates/skills/nx-workspace-patterns/SKILL.md +0 -452
  216. package/templates/skills/openapi-spec-generation/SKILL.md +0 -1028
  217. package/templates/skills/paypal-integration/SKILL.md +0 -467
  218. package/templates/skills/pci-compliance/SKILL.md +0 -466
  219. package/templates/skills/postgresql/SKILL.md +0 -204
  220. package/templates/skills/projection-patterns/SKILL.md +0 -490
  221. package/templates/skills/prometheus-configuration/SKILL.md +0 -392
  222. package/templates/skills/prompt-engineering-patterns/SKILL.md +0 -201
  223. package/templates/skills/prompt-engineering-patterns/assets/few-shot-examples.json +0 -106
  224. package/templates/skills/prompt-engineering-patterns/assets/prompt-template-library.md +0 -246
  225. package/templates/skills/prompt-engineering-patterns/references/chain-of-thought.md +0 -399
  226. package/templates/skills/prompt-engineering-patterns/references/few-shot-learning.md +0 -369
  227. package/templates/skills/prompt-engineering-patterns/references/prompt-optimization.md +0 -414
  228. package/templates/skills/prompt-engineering-patterns/references/prompt-templates.md +0 -470
  229. package/templates/skills/prompt-engineering-patterns/references/system-prompts.md +0 -189
  230. package/templates/skills/prompt-engineering-patterns/scripts/optimize-prompt.py +0 -279
  231. package/templates/skills/python-packaging/SKILL.md +0 -870
  232. package/templates/skills/python-performance-optimization/SKILL.md +0 -869
  233. package/templates/skills/python-testing-patterns/SKILL.md +0 -907
  234. package/templates/skills/rag-implementation/SKILL.md +0 -403
  235. package/templates/skills/react-modernization/SKILL.md +0 -513
  236. package/templates/skills/react-native-architecture/SKILL.md +0 -671
  237. package/templates/skills/react-state-management/SKILL.md +0 -429
  238. package/templates/skills/risk-metrics-calculation/SKILL.md +0 -555
  239. package/templates/skills/rust-async-patterns/SKILL.md +0 -517
  240. package/templates/skills/secrets-management/SKILL.md +0 -346
  241. package/templates/skills/security-requirement-extraction/SKILL.md +0 -677
  242. package/templates/skills/security-review/SKILL.md +0 -78
  243. package/templates/skills/shellcheck-configuration/SKILL.md +0 -454
  244. package/templates/skills/similarity-search-patterns/SKILL.md +0 -558
  245. package/templates/skills/slo-implementation/SKILL.md +0 -329
  246. package/templates/skills/sql-optimization-patterns/SKILL.md +0 -493
  247. package/templates/skills/stripe-integration/SKILL.md +0 -442
  248. package/templates/skills/systematic-debugging/SKILL.md +0 -57
  249. package/templates/skills/tailwind-design-system/SKILL.md +0 -666
  250. package/templates/skills/temporal-python-testing/SKILL.md +0 -158
  251. package/templates/skills/temporal-python-testing/resources/integration-testing.md +0 -455
  252. package/templates/skills/temporal-python-testing/resources/local-setup.md +0 -553
  253. package/templates/skills/temporal-python-testing/resources/replay-testing.md +0 -462
  254. package/templates/skills/temporal-python-testing/resources/unit-testing.md +0 -328
  255. package/templates/skills/terraform-module-library/SKILL.md +0 -249
  256. package/templates/skills/terraform-module-library/references/aws-modules.md +0 -63
  257. package/templates/skills/test-driven-development/SKILL.md +0 -46
  258. package/templates/skills/threat-mitigation-mapping/SKILL.md +0 -745
  259. package/templates/skills/track-management/SKILL.md +0 -593
  260. package/templates/skills/typescript-advanced-types/SKILL.md +0 -717
  261. package/templates/skills/ui-ux-pro-max/SKILL.md +0 -352
  262. package/templates/skills/ui-ux-pro-max/data/charts.csv +0 -26
  263. package/templates/skills/ui-ux-pro-max/data/colors.csv +0 -97
  264. package/templates/skills/ui-ux-pro-max/data/icons.csv +0 -101
  265. package/templates/skills/ui-ux-pro-max/data/landing.csv +0 -31
  266. package/templates/skills/ui-ux-pro-max/data/products.csv +0 -97
  267. package/templates/skills/ui-ux-pro-max/data/prompts.csv +0 -24
  268. package/templates/skills/ui-ux-pro-max/data/react-performance.csv +0 -45
  269. package/templates/skills/ui-ux-pro-max/data/styles.csv +0 -59
  270. package/templates/skills/ui-ux-pro-max/data/typography.csv +0 -58
  271. package/templates/skills/ui-ux-pro-max/data/ui-reasoning.csv +0 -101
  272. package/templates/skills/ui-ux-pro-max/data/ux-guidelines.csv +0 -100
  273. package/templates/skills/ui-ux-pro-max/data/web-interface.csv +0 -31
  274. package/templates/skills/ui-ux-pro-max/scripts/core.py +0 -258
  275. package/templates/skills/ui-ux-pro-max/scripts/design_system.py +0 -547
  276. package/templates/skills/ui-ux-pro-max/scripts/search.py +0 -76
  277. package/templates/skills/uv-package-manager/SKILL.md +0 -831
  278. package/templates/skills/vector-index-tuning/SKILL.md +0 -521
  279. package/templates/skills/wcag-audit-patterns/SKILL.md +0 -555
  280. package/templates/skills/workflow-orchestration-patterns/SKILL.md +0 -316
  281. package/templates/skills/workflow-patterns/SKILL.md +0 -623
  282. package/templates/skills/writing-plans/SKILL.md +0 -64
@@ -1,467 +0,0 @@
1
- ---
2
- name: paypal-integration
3
- description: Integrate PayPal payment processing with support for express checkout, subscriptions, and refund management. Use when implementing PayPal payments, processing online transactions, or building e-commerce checkout flows.
4
- ---
5
-
6
- # PayPal Integration
7
-
8
- Master PayPal payment integration including Express Checkout, IPN handling, recurring billing, and refund workflows.
9
-
10
- ## When to Use This Skill
11
-
12
- - Integrating PayPal as a payment option
13
- - Implementing express checkout flows
14
- - Setting up recurring billing with PayPal
15
- - Processing refunds and payment disputes
16
- - Handling PayPal webhooks (IPN)
17
- - Supporting international payments
18
- - Implementing PayPal subscriptions
19
-
20
- ## Core Concepts
21
-
22
- ### 1. Payment Products
23
- **PayPal Checkout**
24
- - One-time payments
25
- - Express checkout experience
26
- - Guest and PayPal account payments
27
-
28
- **PayPal Subscriptions**
29
- - Recurring billing
30
- - Subscription plans
31
- - Automatic renewals
32
-
33
- **PayPal Payouts**
34
- - Send money to multiple recipients
35
- - Marketplace and platform payments
36
-
37
- ### 2. Integration Methods
38
- **Client-Side (JavaScript SDK)**
39
- - Smart Payment Buttons
40
- - Hosted payment flow
41
- - Minimal backend code
42
-
43
- **Server-Side (REST API)**
44
- - Full control over payment flow
45
- - Custom checkout UI
46
- - Advanced features
47
-
48
- ### 3. IPN (Instant Payment Notification)
49
- - Webhook-like payment notifications
50
- - Asynchronous payment updates
51
- - Verification required
52
-
53
- ## Quick Start
54
-
55
- ```javascript
56
- // Frontend - PayPal Smart Buttons
57
- <div id="paypal-button-container"></div>
58
-
59
- <script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID&currency=USD"></script>
60
- <script>
61
- paypal.Buttons({
62
- createOrder: function(data, actions) {
63
- return actions.order.create({
64
- purchase_units: [{
65
- amount: {
66
- value: '25.00'
67
- }
68
- }]
69
- });
70
- },
71
- onApprove: function(data, actions) {
72
- return actions.order.capture().then(function(details) {
73
- // Payment successful
74
- console.log('Transaction completed by ' + details.payer.name.given_name);
75
-
76
- // Send to backend for verification
77
- fetch('/api/paypal/capture', {
78
- method: 'POST',
79
- headers: {'Content-Type': 'application/json'},
80
- body: JSON.stringify({orderID: data.orderID})
81
- });
82
- });
83
- }
84
- }).render('#paypal-button-container');
85
- </script>
86
- ```
87
-
88
- ```python
89
- # Backend - Verify and capture order
90
- from paypalrestsdk import Payment
91
- import paypalrestsdk
92
-
93
- paypalrestsdk.configure({
94
- "mode": "sandbox", # or "live"
95
- "client_id": "YOUR_CLIENT_ID",
96
- "client_secret": "YOUR_CLIENT_SECRET"
97
- })
98
-
99
- def capture_paypal_order(order_id):
100
- """Capture a PayPal order."""
101
- payment = Payment.find(order_id)
102
-
103
- if payment.execute({"payer_id": payment.payer.payer_info.payer_id}):
104
- # Payment successful
105
- return {
106
- 'status': 'success',
107
- 'transaction_id': payment.id,
108
- 'amount': payment.transactions[0].amount.total
109
- }
110
- else:
111
- # Payment failed
112
- return {
113
- 'status': 'failed',
114
- 'error': payment.error
115
- }
116
- ```
117
-
118
- ## Express Checkout Implementation
119
-
120
- ### Server-Side Order Creation
121
- ```python
122
- import requests
123
- import json
124
-
125
- class PayPalClient:
126
- def __init__(self, client_id, client_secret, mode='sandbox'):
127
- self.client_id = client_id
128
- self.client_secret = client_secret
129
- self.base_url = 'https://api-m.sandbox.paypal.com' if mode == 'sandbox' else 'https://api-m.paypal.com'
130
- self.access_token = self.get_access_token()
131
-
132
- def get_access_token(self):
133
- """Get OAuth access token."""
134
- url = f"{self.base_url}/v1/oauth2/token"
135
- headers = {"Accept": "application/json", "Accept-Language": "en_US"}
136
-
137
- response = requests.post(
138
- url,
139
- headers=headers,
140
- data={"grant_type": "client_credentials"},
141
- auth=(self.client_id, self.client_secret)
142
- )
143
-
144
- return response.json()['access_token']
145
-
146
- def create_order(self, amount, currency='USD'):
147
- """Create a PayPal order."""
148
- url = f"{self.base_url}/v2/checkout/orders"
149
- headers = {
150
- "Content-Type": "application/json",
151
- "Authorization": f"Bearer {self.access_token}"
152
- }
153
-
154
- payload = {
155
- "intent": "CAPTURE",
156
- "purchase_units": [{
157
- "amount": {
158
- "currency_code": currency,
159
- "value": str(amount)
160
- }
161
- }]
162
- }
163
-
164
- response = requests.post(url, headers=headers, json=payload)
165
- return response.json()
166
-
167
- def capture_order(self, order_id):
168
- """Capture payment for an order."""
169
- url = f"{self.base_url}/v2/checkout/orders/{order_id}/capture"
170
- headers = {
171
- "Content-Type": "application/json",
172
- "Authorization": f"Bearer {self.access_token}"
173
- }
174
-
175
- response = requests.post(url, headers=headers)
176
- return response.json()
177
-
178
- def get_order_details(self, order_id):
179
- """Get order details."""
180
- url = f"{self.base_url}/v2/checkout/orders/{order_id}"
181
- headers = {
182
- "Authorization": f"Bearer {self.access_token}"
183
- }
184
-
185
- response = requests.get(url, headers=headers)
186
- return response.json()
187
- ```
188
-
189
- ## IPN (Instant Payment Notification) Handling
190
-
191
- ### IPN Verification and Processing
192
- ```python
193
- from flask import Flask, request
194
- import requests
195
- from urllib.parse import parse_qs
196
-
197
- app = Flask(__name__)
198
-
199
- @app.route('/ipn', methods=['POST'])
200
- def handle_ipn():
201
- """Handle PayPal IPN notifications."""
202
- # Get IPN message
203
- ipn_data = request.form.to_dict()
204
-
205
- # Verify IPN with PayPal
206
- if not verify_ipn(ipn_data):
207
- return 'IPN verification failed', 400
208
-
209
- # Process IPN based on transaction type
210
- payment_status = ipn_data.get('payment_status')
211
- txn_type = ipn_data.get('txn_type')
212
-
213
- if payment_status == 'Completed':
214
- handle_payment_completed(ipn_data)
215
- elif payment_status == 'Refunded':
216
- handle_refund(ipn_data)
217
- elif payment_status == 'Reversed':
218
- handle_chargeback(ipn_data)
219
-
220
- return 'IPN processed', 200
221
-
222
- def verify_ipn(ipn_data):
223
- """Verify IPN message authenticity."""
224
- # Add 'cmd' parameter
225
- verify_data = ipn_data.copy()
226
- verify_data['cmd'] = '_notify-validate'
227
-
228
- # Send back to PayPal for verification
229
- paypal_url = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr' # or production URL
230
-
231
- response = requests.post(paypal_url, data=verify_data)
232
-
233
- return response.text == 'VERIFIED'
234
-
235
- def handle_payment_completed(ipn_data):
236
- """Process completed payment."""
237
- txn_id = ipn_data.get('txn_id')
238
- payer_email = ipn_data.get('payer_email')
239
- mc_gross = ipn_data.get('mc_gross')
240
- item_name = ipn_data.get('item_name')
241
-
242
- # Check if already processed (prevent duplicates)
243
- if is_transaction_processed(txn_id):
244
- return
245
-
246
- # Update database
247
- # Send confirmation email
248
- # Fulfill order
249
- print(f"Payment completed: {txn_id}, Amount: ${mc_gross}")
250
-
251
- def handle_refund(ipn_data):
252
- """Handle refund."""
253
- parent_txn_id = ipn_data.get('parent_txn_id')
254
- mc_gross = ipn_data.get('mc_gross')
255
-
256
- # Process refund in your system
257
- print(f"Refund processed: {parent_txn_id}, Amount: ${mc_gross}")
258
-
259
- def handle_chargeback(ipn_data):
260
- """Handle payment reversal/chargeback."""
261
- txn_id = ipn_data.get('txn_id')
262
- reason_code = ipn_data.get('reason_code')
263
-
264
- # Handle chargeback
265
- print(f"Chargeback: {txn_id}, Reason: {reason_code}")
266
- ```
267
-
268
- ## Subscription/Recurring Billing
269
-
270
- ### Create Subscription Plan
271
- ```python
272
- def create_subscription_plan(name, amount, interval='MONTH'):
273
- """Create a subscription plan."""
274
- client = PayPalClient(CLIENT_ID, CLIENT_SECRET)
275
-
276
- url = f"{client.base_url}/v1/billing/plans"
277
- headers = {
278
- "Content-Type": "application/json",
279
- "Authorization": f"Bearer {client.access_token}"
280
- }
281
-
282
- payload = {
283
- "product_id": "PRODUCT_ID", # Create product first
284
- "name": name,
285
- "billing_cycles": [{
286
- "frequency": {
287
- "interval_unit": interval,
288
- "interval_count": 1
289
- },
290
- "tenure_type": "REGULAR",
291
- "sequence": 1,
292
- "total_cycles": 0, # Infinite
293
- "pricing_scheme": {
294
- "fixed_price": {
295
- "value": str(amount),
296
- "currency_code": "USD"
297
- }
298
- }
299
- }],
300
- "payment_preferences": {
301
- "auto_bill_outstanding": True,
302
- "setup_fee": {
303
- "value": "0",
304
- "currency_code": "USD"
305
- },
306
- "setup_fee_failure_action": "CONTINUE",
307
- "payment_failure_threshold": 3
308
- }
309
- }
310
-
311
- response = requests.post(url, headers=headers, json=payload)
312
- return response.json()
313
-
314
- def create_subscription(plan_id, subscriber_email):
315
- """Create a subscription for a customer."""
316
- client = PayPalClient(CLIENT_ID, CLIENT_SECRET)
317
-
318
- url = f"{client.base_url}/v1/billing/subscriptions"
319
- headers = {
320
- "Content-Type": "application/json",
321
- "Authorization": f"Bearer {client.access_token}"
322
- }
323
-
324
- payload = {
325
- "plan_id": plan_id,
326
- "subscriber": {
327
- "email_address": subscriber_email
328
- },
329
- "application_context": {
330
- "return_url": "https://yourdomain.com/subscription/success",
331
- "cancel_url": "https://yourdomain.com/subscription/cancel"
332
- }
333
- }
334
-
335
- response = requests.post(url, headers=headers, json=payload)
336
- subscription = response.json()
337
-
338
- # Get approval URL
339
- for link in subscription.get('links', []):
340
- if link['rel'] == 'approve':
341
- return {
342
- 'subscription_id': subscription['id'],
343
- 'approval_url': link['href']
344
- }
345
- ```
346
-
347
- ## Refund Workflows
348
-
349
- ```python
350
- def create_refund(capture_id, amount=None, note=None):
351
- """Create a refund for a captured payment."""
352
- client = PayPalClient(CLIENT_ID, CLIENT_SECRET)
353
-
354
- url = f"{client.base_url}/v2/payments/captures/{capture_id}/refund"
355
- headers = {
356
- "Content-Type": "application/json",
357
- "Authorization": f"Bearer {client.access_token}"
358
- }
359
-
360
- payload = {}
361
- if amount:
362
- payload["amount"] = {
363
- "value": str(amount),
364
- "currency_code": "USD"
365
- }
366
-
367
- if note:
368
- payload["note_to_payer"] = note
369
-
370
- response = requests.post(url, headers=headers, json=payload)
371
- return response.json()
372
-
373
- def get_refund_details(refund_id):
374
- """Get refund details."""
375
- client = PayPalClient(CLIENT_ID, CLIENT_SECRET)
376
-
377
- url = f"{client.base_url}/v2/payments/refunds/{refund_id}"
378
- headers = {
379
- "Authorization": f"Bearer {client.access_token}"
380
- }
381
-
382
- response = requests.get(url, headers=headers)
383
- return response.json()
384
- ```
385
-
386
- ## Error Handling
387
-
388
- ```python
389
- class PayPalError(Exception):
390
- """Custom PayPal error."""
391
- pass
392
-
393
- def handle_paypal_api_call(api_function):
394
- """Wrapper for PayPal API calls with error handling."""
395
- try:
396
- result = api_function()
397
- return result
398
- except requests.exceptions.RequestException as e:
399
- # Network error
400
- raise PayPalError(f"Network error: {str(e)}")
401
- except Exception as e:
402
- # Other errors
403
- raise PayPalError(f"PayPal API error: {str(e)}")
404
-
405
- # Usage
406
- try:
407
- order = handle_paypal_api_call(lambda: client.create_order(25.00))
408
- except PayPalError as e:
409
- # Handle error appropriately
410
- log_error(e)
411
- ```
412
-
413
- ## Testing
414
-
415
- ```python
416
- # Use sandbox credentials
417
- SANDBOX_CLIENT_ID = "..."
418
- SANDBOX_SECRET = "..."
419
-
420
- # Test accounts
421
- # Create test buyer and seller accounts at developer.paypal.com
422
-
423
- def test_payment_flow():
424
- """Test complete payment flow."""
425
- client = PayPalClient(SANDBOX_CLIENT_ID, SANDBOX_SECRET, mode='sandbox')
426
-
427
- # Create order
428
- order = client.create_order(10.00)
429
- assert 'id' in order
430
-
431
- # Get approval URL
432
- approval_url = next((link['href'] for link in order['links'] if link['rel'] == 'approve'), None)
433
- assert approval_url is not None
434
-
435
- # After approval (manual step with test account)
436
- # Capture order
437
- # captured = client.capture_order(order['id'])
438
- # assert captured['status'] == 'COMPLETED'
439
- ```
440
-
441
- ## Resources
442
-
443
- - **references/express-checkout.md**: Express Checkout implementation guide
444
- - **references/ipn-handling.md**: IPN verification and processing
445
- - **references/refund-workflows.md**: Refund handling patterns
446
- - **references/billing-agreements.md**: Recurring billing setup
447
- - **assets/paypal-client.py**: Production PayPal client
448
- - **assets/ipn-processor.py**: IPN webhook processor
449
- - **assets/recurring-billing.py**: Subscription management
450
-
451
- ## Best Practices
452
-
453
- 1. **Always Verify IPN**: Never trust IPN without verification
454
- 2. **Idempotent Processing**: Handle duplicate IPN notifications
455
- 3. **Error Handling**: Implement robust error handling
456
- 4. **Logging**: Log all transactions and errors
457
- 5. **Test Thoroughly**: Use sandbox extensively
458
- 6. **Webhook Backup**: Don't rely solely on client-side callbacks
459
- 7. **Currency Handling**: Always specify currency explicitly
460
-
461
- ## Common Pitfalls
462
-
463
- - **Not Verifying IPN**: Accepting IPN without verification
464
- - **Duplicate Processing**: Not checking for duplicate transactions
465
- - **Wrong Environment**: Mixing sandbox and production URLs/credentials
466
- - **Missing Webhooks**: Not handling all payment states
467
- - **Hardcoded Values**: Not making configurable for different environments